Hi!
I’m just trying a simple program to get me started but I don’t understand what my Particle is doing.
I’ve connected a switch between D2 and GND with an IF statement dependent on it’s state. The whole thing should run on a button-push on IFTTT but I get the same response (ON, OFF, ON, OFF) irrespective of whether the switch is engaged or not.
I’ve removed the switch and just clamped the wires together (in case it was a fault with the switch) and it’s made no difference.
Please see the code below, if you’re able to help I’d really appreciate it. I know it’s probably a dead simple one, it’s just to get me started on a bigger project.
Thanks!
volatile bool doToggle = false;
int led1 = D7;
int posDetector1 = D2;
int posStatus1 = LOW;
void setup() {
pinMode(led1, OUTPUT);
Particle.function("toggleBlink", toggleBlink);
pinMode(posDetector1, INPUT_PULLDOWN);
Particle.variable("posStatus1", &posStatus1, INT);
}
void loop() {
if (doToggle == true) {
posStatus1 = digitalRead(posDetector1);
if (posStatus1 == LOW) {
digitalWrite(led1, HIGH);
delay(300);
digitalWrite(led1, LOW);
delay(300);
digitalWrite(led1, HIGH);
delay(300);
digitalWrite(led1, LOW);
delay(300);
digitalWrite(led1, HIGH);
delay(300);
digitalWrite(led1, LOW);
delay(300);
digitalWrite(led1, HIGH);
delay(300);
digitalWrite(led1, LOW);
doToggle = false;
}
else {
digitalWrite(led1, HIGH);
delay(3000);
digitalWrite(led1, LOW);
doToggle = false;
}
}
}
int toggleBlink(String command) {
doToggle = true;
}