I am working on something with the Internet Button(IB) and I am having trouble understanding the order within he code. Basically what I am looking to accomplish is having three LEDS of a certain color as a group for each button (2, 3, 4) and when a button is pressed the corresponding LED group turns off. This part I have…but for only one button. Meaning if after the IB powers up and the LEDs light up, if I press button 2, button 2’s LED group turns off. However, pressing buttons 3 or 4 do not turn off their LED group.
I guess I am unclear on where I need to place code so that it separates out these three individual commands.
Just to give a quick picture of what my project is: I want to press a button in the a.m. and it go off. (I am implementing timer function to reactivate after 22hrs). Then my wife press a button in the a.m. and my oldest son press the remaining button in the a.m.
After each individual has pressed their button, the LED group for that button goes off and remains off until the 22hr timer has reached its end.
I have successfully programmed the internet button to function the way I intended. Taking advice from my buddy at the office today, I scratched most of the code and worked from the bottom up again. Here is the final result:
// This #include statement was automatically added by the Particle IDE.
#include "SparkTime/SparkTime.h"
// This #include statement was automatically added by the Particle IDE.
#include "InternetButton/InternetButton.h"
InternetButton b = InternetButton();
bool one = true;
bool two = true;
bool three = true;
bool four = true;
//7200 for testing
Timer oneTimer(7200, activateOne);
Timer twoTimer(7200, activateTwo);
Timer threeTimer(7200, activateThree);
Timer fourTimer(7200, activateFour);
void setup() {
b.begin();
activateOne();
activateTwo();
activateThree();
activateFour();
}
void loop() {
if(b.buttonOn(1)){
if (one) {
deactivateOne();
oneTimer.start();
}
} else
if(b.buttonOn(2)){
if (two) {
deactivateTwo();
twoTimer.start();
}
} else
if(b.buttonOn(3)){
if (three) {
deactivateThree();
threeTimer.start();
}
} else
if(b.buttonOn(4)){
if (four) {
deactivateFour();
fourTimer.start();
}
}
}
void deactivateOne(){
one = false;
b.ledOff(11);
b.ledOff(1);
}
void activateOne(){
one = true;
b.ledOn(11, 255, 0, 0);
b.ledOn(1, 255, 0, 0);
}
void deactivateTwo(){
two = false;
b.ledOff(2);
b.ledOff(3);
b.ledOff(4);
}
void activateTwo(){
two = true;
b.ledOn(2, 30, 255, 0);
b.ledOn(3, 30, 255, 0);
b.ledOn(4, 30, 255, 0);
}
void deactivateThree(){
three = false;
b.ledOff(5);
b.ledOff(6);
b.ledOff(7);
}
void activateThree(){
three = true;
b.ledOn(5, 0, 145, 255);
b.ledOn(6, 0, 145, 255);
b.ledOn(7, 0, 145, 255);
}
void deactivateFour(){
four = false;
b.ledOff(8);
b.ledOff(9);
b.ledOff(10);
}
void activateFour(){
four = true;
b.ledOn(8, 255, 0, 132);
b.ledOn(9, 255, 0, 132);
b.ledOn(10, 255, 0, 132);
}