Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // home_automation_lights.ino
- #include <SerialCommand.h>
- #include <RCSwitch.h>
- #define APP_SERIAL_DEBUG // comment this when in production mode
- const unsigned int SERIAL_PORT_BAUDRATE = 9600; // change this accordingly
- const byte RC_SWITCH_TX_PIN = 10; // change this accordingly
- char* LIGHT_ON_CODE = "000000000001010100010001"; // change this accordingly
- char* LIGHT_OFF_CODE = "000000000001010100010001"; // change this accordingly
- SerialCommand sCmd(Serial); // the SerialCommand object used for string parsing over serial port
- RCSwitch rcSwitch = RCSwitch(); // the RCSwitch object used for RF commands
- // this gets called when you send "LIGHT_ON" string on the serial port
- void lightOn() {
- #ifdef APP_SERIAL_DEBUG
- Serial.println(F("Sending LIGHT_ON command..."));
- #endif
- rcSwitch.send(LIGHT_ON_CODE);
- }
- // this gets called when you send "LIGHT_OFF" string on the serial port
- void lightOff() {
- #ifdef APP_SERIAL_DEBUG
- Serial.println(F("Sending LIGHT_OFF command..."));
- #endif
- rcSwitch.send(LIGHT_OFF_CODE);
- }
- void noCmdMatched() {
- Serial.println(F("Invalid command sent!"));
- }
- void setup() {
- Serial.begin(SERIAL_PORT_BAUDRATE); // set serial port communications baudrate
- // Setup callbacks for SerialCommand commands
- sCmd.addCommand(F("LIGHT_ON"), lightOn); // handler/callback setup for turning light on
- sCmd.addCommand(F("LIGHT_OFF"), lightOff); // handler/callback setup for turning light off
- sCmd.setDefaultHandler(noCmdMatched); // handler/callback setup for unknown command
- // Transmitter is connected to Arduino Pin RC_SWITCH_TX_PIN set up above
- rcSwitch.enableTransmit(RC_SWITCH_TX_PIN);
- #ifdef APP_SERIAL_DEBUG
- Serial.println(F("System ready..."));
- #endif
- }
- void loop() {
- sCmd.readSerial(); // process serial commands
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement