Created
July 10, 2012 14:21
-
-
Save redlegoman/3083580 to your computer and use it in GitHub Desktop.
remoteswitch_toggle.ino
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// VARS --------------------------------------------- | |
int incomingByte = 0; // for incoming serial data | |
int pin = 10; // pin connected to RF transmitter (pin 2) | |
#define d4 700 // | |
#define d2 350 // | |
#define d1 175 // | |
//--------------------------------------------------- | |
void setup(){ | |
Serial.begin(9600); | |
Serial.println("Type \"A\" to switch on"); | |
Serial.println("Type \"a\" to switch off"); | |
} | |
void loop(){ | |
if (Serial.available() > 0) { | |
// read the incoming byte: | |
incomingByte = Serial.read(); | |
if(incomingByte == 65) { //"A" | |
Aon();Aon();Aon();Aon(); // toggle the switch on or off here | |
Serial.println("Switching A on..."); | |
}// end if incomingbyte | |
if(incomingByte == 97) { //"a" | |
Aoff();Aoff();Aoff();Aoff(); // toggle the switch on or off here | |
Serial.println("Switching A off..."); | |
}// end if incomingbyte | |
} // end if serial available | |
}// end void loop | |
//----------------------------------------------------------- | |
void pulse0(){ | |
digitalWrite(pin, HIGH); | |
delayMicroseconds(d2); | |
digitalWrite(pin, LOW); | |
delayMicroseconds(d2); | |
delayMicroseconds(d2); | |
delayMicroseconds(d2); | |
delayMicroseconds(d2); | |
delayMicroseconds(d2); | |
delayMicroseconds(d2); | |
delayMicroseconds(d2); | |
delayMicroseconds(d1); | |
} | |
void pulse1(){ | |
digitalWrite(pin, HIGH); | |
delayMicroseconds(d2); | |
digitalWrite(pin, LOW); | |
delayMicroseconds(d4); | |
delayMicroseconds(d2); | |
delayMicroseconds(d1); | |
} | |
void pulse2(){ | |
digitalWrite(pin, HIGH); | |
delayMicroseconds(d2); | |
digitalWrite(pin, LOW); | |
delayMicroseconds(d1); | |
digitalWrite(pin, HIGH); | |
delayMicroseconds(d2); | |
digitalWrite(pin, LOW); | |
delayMicroseconds(d4); | |
delayMicroseconds(d2); | |
delayMicroseconds(d1); | |
} | |
void pulse3(){ | |
digitalWrite(pin, HIGH); | |
delayMicroseconds(d2); | |
digitalWrite(pin, LOW); | |
delayMicroseconds(d1); | |
digitalWrite(pin, HIGH); | |
delayMicroseconds(d2); | |
digitalWrite(pin, LOW); | |
delayMicroseconds(d1); | |
digitalWrite(pin, HIGH); | |
delayMicroseconds(d2); | |
digitalWrite(pin, LOW); | |
delayMicroseconds(d4); | |
delayMicroseconds(d2); | |
delayMicroseconds(d1); | |
} | |
void Aon(){ | |
pulse0();pulse2();pulse2();pulse2();pulse2();pulse2();pulse1();pulse3();pulse2();pulse1(); | |
pulse3();pulse1();pulse2();pulse2();pulse2();pulse2();pulse3();pulse1();pulse2();pulse3(); | |
pulse2();pulse2();pulse1();pulse2();pulse3();pulse1();pulse3();pulse2(); | |
pulse1();// swap for off | |
pulse2();// swap for off | |
pulse3();pulse1();pulse3();pulse1(); | |
delay(50); | |
} | |
void Aoff(){ | |
pulse0();pulse2();pulse2();pulse2();pulse2();pulse2();pulse1();pulse3();pulse2();pulse1(); | |
pulse3();pulse1();pulse2();pulse2();pulse2();pulse2();pulse3();pulse1();pulse2();pulse3(); | |
pulse2();pulse2();pulse1();pulse2();pulse3();pulse1();pulse3();pulse2(); | |
pulse2();// swap for on | |
pulse1();// swap for on | |
pulse3();pulse1();pulse3();pulse1(); | |
delay(50); | |
} | |
void Bon(){ | |
pulse0();pulse2();pulse2();pulse2();pulse2();pulse2();pulse1();pulse3();pulse2();pulse1(); | |
pulse3();pulse1();pulse2();pulse2();pulse2();pulse2();pulse3();pulse1();pulse2();pulse3(); | |
pulse2();pulse2();pulse1();pulse2();pulse3();pulse1();pulse3();pulse2(); | |
pulse1();// swap for off | |
pulse2();// swap for off | |
pulse3();pulse1();pulse2();pulse2(); | |
delay(50); | |
} | |
void Boff(){ | |
pulse0();pulse2();pulse2();pulse2();pulse2();pulse2();pulse1();pulse3();pulse2();pulse1(); | |
pulse3();pulse1();pulse2();pulse2();pulse2();pulse2();pulse3();pulse1();pulse2();pulse3(); | |
pulse2();pulse2();pulse1();pulse2();pulse3();pulse1();pulse3();pulse2(); | |
pulse2();// swap for on | |
pulse1();// swap for on | |
pulse3();pulse1();pulse2();pulse2(); | |
delay(50); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment