diff options
Diffstat (limited to 'trasmitter/sender.ino')
-rw-r--r-- | trasmitter/sender.ino | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/trasmitter/sender.ino b/trasmitter/sender.ino new file mode 100644 index 0000000..e53bd72 --- /dev/null +++ b/trasmitter/sender.ino @@ -0,0 +1,76 @@ +const uint16_t arrOn[] = { + 2, 2, 2, 2, 2, 2, 4, 2, 4, 2, 2, 3, 2, 2, 3, 2, 2, 2, 2, 2, 4, 2, 2, 2, 2, 3, 2, 3, 4, 2, +}; +const int nOnLen = sizeof(arrOn)/sizeof(uint16_t); +const uint16_t arrOff[] = { + 2, 2, 2, 2, 2, 2, 4, 2, 4, 2, 2, 3, 2, 2, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 4, 3, 3, 4, 2, +}; +const int nOffLen = sizeof(arrOff)/sizeof(uint16_t); +const int nTxPin = 7; // Arduino digital pin you're using for radio data. +const int pulseScale = 260; // usec per sample unit + + +void transmitArray(const uint16_t pulses[], int pulseCount) { + for (int repeat=0; repeat < 3; ++repeat) { + for(int pulse = 0; pulse < pulseCount; ++pulse) { + int pulseWidth = pulses[pulse]; + + digitalWrite(nTxPin, HIGH); + // Widths are in units of 500us, for the full-period square wave + delayMicroseconds(pulseScale*pulseWidth); + + digitalWrite(nTxPin, LOW); + delayMicroseconds(pulseScale*pulseWidth); + } + } +} + +void sendTrain(const uint16_t pulses[], int pulseCount) { + transmitArray(pulses,pulseCount); + delay(1000); + transmitArray(pulses,pulseCount); + delay(2000); + transmitArray(pulses,pulseCount); +} + + +/** + * 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(arrOn, nOnLen); + } + + if (nIncomming == 48) { // char code for 0 + Serial.println("OFF"); + sendTrain(arrOff, nOffLen); + } + + Serial.println("Press 0 to turn off heating"); + Serial.println("Press 1 to turn on heating"); + } +}
\ No newline at end of file |