From 065835767dd877d8b0e2ccdbe5b915c5e22bd62a Mon Sep 17 00:00:00 2001 From: dakkar Date: Sat, 9 Jun 2018 12:55:53 +0100 Subject: working CHIP sender --- trasmitter/sender.ino | 93 --------------------------------------------------- 1 file changed, 93 deletions(-) delete mode 100644 trasmitter/sender.ino (limited to 'trasmitter/sender.ino') diff --git a/trasmitter/sender.ino b/trasmitter/sender.ino deleted file mode 100644 index 9373875..0000000 --- a/trasmitter/sender.ino +++ /dev/null @@ -1,93 +0,0 @@ -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 -- cgit v1.2.3