/* * AM-HRR3 transmitter test. * Connect two push switches up to onPin and offPin, pulled high. * * Emits a homeeasy simple protocol ON message when the onPin is brought low, * and vice versa for offPin. * * Barnaby Gray 12/2008. */ int txPin = 13; int onPin = 12; int offPin = 11; void setup() { pinMode(txPin, OUTPUT); pinMode(onPin, INPUT); pinMode(offPin, INPUT); Serial.begin(9600); } void sendBit(boolean b) { if (b) { digitalWrite(txPin, HIGH); delayMicroseconds(1125); digitalWrite(txPin, LOW); delayMicroseconds(375); } else { digitalWrite(txPin, HIGH); delayMicroseconds(375); digitalWrite(txPin, LOW); delayMicroseconds(1125); } } void sendPair(boolean b) { sendBit(false); sendBit(b); } void switchcode(boolean b) { // house code 1 = B sendPair(true); sendPair(false); sendPair(false); sendPair(false); // unit code 2 sendPair(true); sendPair(false); sendPair(false); sendPair(false); // on = 14 sendPair(false); sendPair(true); sendPair(true); sendPair(b); sendBit(false); } void transmit(boolean b) { switchcode(b); delayMicroseconds(10000); switchcode(b); delayMicroseconds(10000); switchcode(b); } void loop() { int val = digitalRead(onPin); if (val == LOW) { transmit(true); } val = digitalRead(offPin); if (val == LOW) { transmit(false); } }