Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- ProTrinket_Lightswithc Program by Duncan Flint
- This arduino sketch controls five RF lightswitches using an RF transmitter. It utilizes a switch connected to pin 5. It is designed for a pro trinket
- Last modified 4/20/2015 (Modification only included clarifying comments)
- */
- #include <RCSwitch.h>
- int switchPin = 5;
- int rfPin = 3;
- RCSwitch mySwitch = RCSwitch(); //Declares new object of classs RCSwitch
- boolean lightsOn = false;
- int numCyclesOn = 0;
- int numCyclesOff = 0;
- void setup()
- {
- pinMode(switchPin, INPUT);
- Serial.begin(9600);
- mySwitch.enableTransmit(rfPin); // Enables transmission on pin 3 of arduino
- mySwitch.setPulseLength(173); // Needed for setup of RF transmitter
- }
- void loop()
- {
- int switchReading = digitalRead(switchPin); // Check if lightswitch is currently on or off
- Serial.print(switchReading);
- if (switchReading == 1) // Switch reading a 1, that means the switch is in the "off" position
- {
- if ((numCyclesOff == 0) && (lightsOn == true)) // This if statement means that the lights are only turned off if this is the first cycle that the switch has been in the "off" position
- {
- numCyclesOn = 0;
- mySwitch.send(87356, 24); // Outlet 1 off. These codes are from capturing the RF transmissions made by the remote using an RF receiver
- mySwitch.send(87500, 24); // Outlet 2 off
- mySwitch.send(87820, 24); // Outlet 3 off
- mySwitch.send(89356, 24); // Outlet 4 off
- mySwitch.send(95500, 24); // Outlet 5 off
- lightsOn = false;
- numCyclesOff++;
- }
- else
- {
- numCyclesOff++;
- }
- }
- else if (switchReading == 0) // Switch reading a 0, that means the switch is in the "on" position
- {
- if ((numCyclesOn == 0) && (lightsOn == false)) // This if statement means that the lights are only turned on if this is the first cycle that the switch has been in the "on" position
- {
- numCyclesOff = 0;
- mySwitch.send(87347, 24); // Outlet 1 on
- mySwitch.send(87491, 24); // Outlet 2 on
- mySwitch.send(87811, 24); // Outlet 3 on
- mySwitch.send(89347, 24); // Outlet 4 on
- mySwitch.send(95491, 24); // Outlet 5 on
- lightsOn = true;
- numCyclesOn++;
- }
- else
- {
- numCyclesOn++;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement