Created
November 12, 2014 20:41
-
-
Save geek/033adba967140e7e4be8 to your computer and use it in GitHub Desktop.
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
#include <MySensor.h> | |
#include <SPI.h> | |
#define LED_PIN 8 | |
#define RADIO_ID 20 | |
#define CHILD_ID 1 | |
MySensor gw; | |
MyMessage lightMsg(CHILD_ID, V_LIGHT); | |
void setup() | |
{ | |
gw.begin(incomingMessage, RADIO_ID); | |
pinMode(LED_PIN, OUTPUT); | |
// Register the LED Light with the gateway | |
gw.present(CHILD_ID, S_LIGHT); | |
gw.sendSketchInfo("LED", "1.0"); | |
} | |
void loop() | |
{ | |
gw.process(); | |
} | |
void incomingMessage(const MyMessage &message) { | |
Serial.println("Got message"); | |
Serial.print(message.type); | |
if (message.type == V_LIGHT) { | |
int isOn = atoi(message.data); | |
Serial.println("Changing to"); | |
Serial.println(message.data); | |
if (isOn == 0) { | |
digitalWrite(LED_PIN, LOW); | |
} | |
else { | |
digitalWrite(LED_PIN, HIGH); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment