diff options
Diffstat (limited to 'trasmitter/arduino/sender.ino')
-rw-r--r-- | trasmitter/arduino/sender.ino | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/trasmitter/arduino/sender.ino b/trasmitter/arduino/sender.ino new file mode 100644 index 0000000..9373875 --- /dev/null +++ b/trasmitter/arduino/sender.ino @@ -0,0 +1,93 @@ +const uint16_t pulseScale = 520; // usec per sample unit + +// alternate HIGH and LOW, first one of each array is HIGH +const uint8_t prologue[] = { + 1,1, 1,1, 1,1, 1,1, 1,1, 1,1, + 2,3, 1,1, 2,2, 1,1, 1,1, 2,1, + 1,1, 1,1, 1,2, 1,1, 1,1, 1,1, + 1,1, 1,1, +}; +const size_t prologueSize = sizeof(prologue) / sizeof(uint8_t); + +const uint8_t epilogue[] = { + 1,2, 2,2, 1,3, // the last value doesn't much matter +}; +const size_t epilogueSize = sizeof(epilogue) / sizeof(uint8_t); + +const uint8_t onSignal[] = { + 2,2, 1,1, 1,1, 1,1, 1,1, 2,1, 1,1, +}; +const size_t onSize = sizeof(onSignal) / sizeof(uint8_t); + +const uint8_t offSignal[] = { + 1,1, 1,1, 1,1, 1,1, 1,1, 2,2, 2,1, +}; +const size_t offSize = sizeof(offSignal) / sizeof(uint8_t); + +const int nTxPin = 7; // Arduino digital pin you're using for radio data. + +void transmitArray(const uint8_t pulses[], size_t pulseCount) { + for(size_t idx = 0; idx < pulseCount; idx+=2) { + digitalWrite(nTxPin, HIGH); + delayMicroseconds(pulseScale*pulses[idx]); + + digitalWrite(nTxPin, LOW); + delayMicroseconds(pulseScale*pulses[idx+1]); + } +} + +void transmitSignal(const uint8_t signal[], size_t signalSize) { + transmitArray(prologue,prologueSize); + transmitArray(signal,signalSize); + transmitArray(epilogue,epilogueSize); +} + +void sendTrain(const uint8_t signal[], size_t signalSize) { + transmitSignal(signal,signalSize); + delay(1000); + transmitSignal(signal,signalSize); + delay(2000); + transmitSignal(signal,signalSize); +} + + +/** + * The setup() function is called when a sketch starts. Used to initialize + * variables, pin modes, start using libraries, etc. The setup function will + * only run once, after each powerup or reset of the Arduino board. + */ +void setup() +{ + pinMode(nTxPin, OUTPUT); + digitalWrite(nTxPin, LOW); + + Serial.begin(9600); + Serial.println("Press 0 to turn off heating"); + Serial.println("Press 1 to turn on heating"); + +} + + +/** + * The loop() function loops consecutively, allowing the program to change and + * respond. Used to actively control the Arduino board. + */ +void loop() +{ + if (Serial.available() > 0) + { + int nIncomming = Serial.read(); + if (nIncomming == 49) { // char code for 1 + Serial.println("ON"); + sendTrain(onSignal,onSize); + } + + if (nIncomming == 48) { // char code for 0 + Serial.println("OFF"); + sendTrain(offSignal,offSize); + } + + Serial.println("Press 0 to turn off heating"); + Serial.println("Press 1 to turn on heating"); + } +}
\ No newline at end of file |