bool lightStatus;
int currentHex;
int controlRGB(String command);
int wait = 1000;
int onoff = 0xFF02FD;
int hrz = 32;
int inputPin = D0;
int ledPin = D1;
int pirState = LOW;
int val = 0;
void setup() {
pinMode( ledPin, OUTPUT );
pinMode(inputPin, INPUT);
lightStatus = false;
Particle.function("lights", controlRGB);
Particle.variable("lightStatus", lightStatus);
}
void loop() {
if ( calibrated() )
{
readTheSensor();
reportTheData();
}
}
void readTheSensor() {
val = digitalRead(inputPin);
}
void lightOnOff(){
irsend.sendNEC(On_Off, 32);
lightStatus = !lightStatus;
}
bool calibrated() {
return millis() - calibrateTime > 0;
}
void setLight(int hex){
if(!lightStatus){
lightOnOff();
delay(wait);
}
irsend.sendNEC(hex,hrz);
}
int controlRGB(String command){
if(command == "onoff"){
lightOnOff();
}
if(command == "code"){
setLight(currentHex);
}
if(command == "red"){
setLight(Red);
}
if(command == "green"){
setLight(Green);
}
if(command == "blue"){
setLight(Blue);
}
if(command == "white"){
setLight(White);
}
if(command == "brighter"){
setLight(Brighter);
}
if(command == "lessBright"){
setLight(Less_Bright);
}
if(command == "flash"){
setLight(Flash);
}
if(command == "fade7"){
setLight(Fade7);
}
if(command == "fade3"){
setLight(Fade3);
}
if(command == "jump3"){
setLight(Jump3);
}
if(command == "jump7"){
setLight(Jump7);
}
if(command == "quick"){
setLight(Quick);
}
if(command == "slow"){
setLight(Slow);
}
if(command == "off"){
if(lightStatus){
lightOnOff();
}
}
if(command == "isoff"){
lightStatus = false;
}
}
Click to Expand
Content Rating
Is this a good/useful/informative piece of content to include in the project? Have your say!
You must login before you can post a comment. .