Last active
September 20, 2016 23:37
-
-
Save aurman/6546221 to your computer and use it in GitHub Desktop.
Arduino On Off Hello
This file contains 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
//***************************************************************************** | |
/// @file | |
/// @brief | |
/// Arduino SmartThings Shield LED Example | |
//***************************************************************************** | |
#include <SoftwareSerial.h> //TODO need to set due to some weird wire language linker, should we absorb this whole library into smartthings | |
#include <SmartThings.h> | |
#define PIN_THING_RX 3 | |
#define PIN_THING_TX 2 | |
SmartThingsCallout_t messageCallout; // call out function forward decalaration | |
SmartThings smartthing(PIN_THING_RX, PIN_THING_TX, messageCallout); // constructor | |
int ledPin = 13; | |
bool isDebugEnabled; // enable or disable debug in this example | |
int stateLED; // state to track last set value of LED | |
void setup() | |
{ | |
// setup default state of global variables | |
isDebugEnabled = true; | |
stateLED = 0; // matches state of hardware pin set below | |
// setup hardware pins | |
pinMode(ledPin, OUTPUT); // define PIN_LED as an output | |
digitalWrite(ledPin, LOW); // set value to LOW (off) to match stateLED=0 | |
if (isDebugEnabled) | |
{ // setup debug serial port | |
Serial.begin(9600); // setup serial with a baud rate of 9600 | |
Serial.println("setup.."); // print out 'setup..' on start | |
} | |
} | |
void loop() | |
{ | |
// run smartthing logic | |
smartthing.run(); | |
} | |
void on() | |
{ | |
stateLED = 1; // save state as 1 (on) | |
digitalWrite(ledPin, HIGH); // turn LED on | |
smartthing.shieldSetLED(0, 0, 1); | |
smartthing.send("on"); // send message to cloud | |
Serial.println("on"); | |
} | |
void off() | |
{ | |
stateLED = 0; // set state to 0 (off) | |
digitalWrite(ledPin, LOW); // turn LED off | |
smartthing.shieldSetLED(0, 0, 0); | |
smartthing.send("off"); // send message to cloud | |
Serial.println("off"); | |
} | |
void hello() | |
{ | |
Serial.println("brobasaur"); | |
smartthing.send("colors!"); | |
smartthing.shieldSetLED(1, 0, 0); | |
delay(200); | |
smartthing.shieldSetLED(0, 1, 0); | |
delay(200); | |
smartthing.shieldSetLED(0, 0, 1); | |
delay(200); | |
smartthing.shieldSetLED(1, 1, 0); | |
delay(200); | |
smartthing.shieldSetLED(1, 1, 1); | |
delay(200); | |
smartthing.shieldSetLED(1, 0, 1); | |
delay(200); | |
smartthing.shieldSetLED(0, 1, 1); | |
delay(200); | |
smartthing.shieldSetLED(3, 2, 1); | |
delay(200); | |
smartthing.shieldSetLED(1, 2, 3); | |
delay(200); | |
smartthing.shieldSetLED(2, 2, 4); | |
delay(200); | |
smartthing.shieldSetLED(4, 3, 1); | |
delay(200); | |
smartthing.shieldSetLED(0, 0, 0); | |
smartthing.send("fancy"); | |
} | |
void messageCallout(String message) | |
{ | |
// if debug is enabled print out the received message | |
if (isDebugEnabled) | |
{ | |
Serial.print("Received message: '"); | |
Serial.print(message); | |
Serial.println("' "); | |
} | |
// if message contents equals to 'on' then call on() function | |
// else if message contents equals to 'off' then call off() function | |
if (message.equals("on")) | |
{ | |
on(); | |
} | |
else if (message.equals("off")) | |
{ | |
off(); | |
} | |
else if (message.equals("hello")) | |
{ | |
hello(); | |
} | |
} |
That makes sense. I'm using the "On/Off Shield (example)" device type and I have this loaded onto my Arduino. However, only the Hello button seems to generate a message and even that doesn't seem to be coming out right. I've attached a picture to show what I'm getting. I feel like there should be something in the 'value' row at the bottom. I crossed out some pieces of information, maybe unnecessarily; hopefully it's not needed to diagnose the problem.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I am also new to this. You definitely need to create the smart things ecosystem device handler that correspond to this arduino sketch.