Skip to content

Instantly share code, notes, and snippets.

@jpettersson
Created September 28, 2010 21:42
Show Gist options
  • Save jpettersson/601845 to your computer and use it in GitHub Desktop.
Save jpettersson/601845 to your computer and use it in GitHub Desktop.
#include <Lighthouse.h>;
Lighthouse lighthouse = Lighthouse('5', '4');
int fanPin = 6;
int coolPin = 7;
char STATE_OFF = '1';
char STATE_FAN = '2';
char STATE_COOL = '3';
char fakeData[3] = {'2', '4', '2'};
void setup() {
pinMode(fanPin, OUTPUT);
digitalWrite(fanPin, LOW);
pinMode(coolPin, OUTPUT);
digitalWrite(coolPin, LOW);
Serial.begin(9600);
lighthouse.setToStateListener(toState);
lighthouse.setReturnDataListener(returnData);
lighthouse.setOnNewDataListener(onNewData);
delay(1000);
lighthouse.setState(STATE_OFF);
}
void loop() {
if (Serial.available() > 0) {
byte b = (byte) Serial.read();
lighthouse.onSerialByte(b);
}
}
void returnData(char* data) {
}
void onNewData(char* data) {
}
void toState(char* data){
char newState = data[0];
if(newState == STATE_OFF) {
off();
}else if(newState == STATE_FAN) {
fan();
}else if(newState == STATE_COOL) {
cool();
}
}
void off() {
digitalWrite(fanPin, LOW);
digitalWrite(coolPin, LOW);
lighthouse.setState(STATE_OFF);
}
void fan() {
digitalWrite(fanPin, HIGH);
digitalWrite(coolPin, LOW);
lighthouse.setState(STATE_FAN);
}
void cool() {
digitalWrite(fanPin, LOW);
digitalWrite(coolPin, HIGH);
lighthouse.setState(STATE_COOL);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment