Light Switch Firmware
The light switch firmware uses Particle Function "switchRelay" to be informed by a remote app if the relay should be switched. A remote App sends the character 1 to turn the relay on, or the character 0 to shut the relay off. "switchRelay" sets variable "relayState" for use in loop(), and calls function "setOutputs" to immediately set the correct state. "relayState" is also a Particle variable so can be retrieved enabling a remote app to discover whether the switch is on or off.
The program loop() continually checks for a HIGH state on pin D0, and if found, recognizes the change as a capacitive touch proximity sense event and so toggles the state of the relay using function "setOutputs()". Otherwise loop() just sets the outputs based on "relayState" by calling function "setOutputs".
A copy of the code is downloadable below - it is copyright Joe Menard 102 but freely licensed under the MIT license. (as is everything on this site). If you read this into the Arduino IDE and cut and paste into Particle web IDE, you should be good to go. A .png of the code is also downloadable in case the image below is not readable. A subset of this code is used in the Power Brick.
The light switch firmware uses Particle Function "switchRelay" to be informed by a remote app if the relay should be switched. A remote App sends the character 1 to turn the relay on, or the character 0 to shut the relay off. "switchRelay" sets variable "relayState" for use in loop(), and calls function "setOutputs" to immediately set the correct state. "relayState" is also a Particle variable so can be retrieved enabling a remote app to discover whether the switch is on or off.
The program loop() continually checks for a HIGH state on pin D0, and if found, recognizes the change as a capacitive touch proximity sense event and so toggles the state of the relay using function "setOutputs()". Otherwise loop() just sets the outputs based on "relayState" by calling function "setOutputs".
A copy of the code is downloadable below - it is copyright Joe Menard 102 but freely licensed under the MIT license. (as is everything on this site). If you read this into the Arduino IDE and cut and paste into Particle web IDE, you should be good to go. A .png of the code is also downloadable in case the image below is not readable. A subset of this code is used in the Power Brick.
![]()
|
![]()
|