I seam to be having a fundamental error with the code below;
int bInput1 = D0;
int bBoardLed = D7;
void setup() {
pinMode(bInput1, INPUT);
pinMode(bBoardLed, OUTPUT);
digitalWrite(bBoardLed, LOW);
}
void loop() {
if (digitalRead(bInput1) == HIGH) {
Particle.publish("#######","on");
digitalWrite(bBoardLed, HIGH);
// delay(1000);
}
else if (digitalRead(bInput1) == LOW) {
Particle.publish("#######","off");
digitalWrite(bBoardLed, LOW);
// delay(1000);
}
else {
}
When running, the local LED will toggle on operating the input from a pushbutton, but the Publish function gives a return value of “off”.
But if I introduce the time delay of 1s to each statement, the code cycles through, toggling the local LED and the published result also toggles.
If during this “delayed” code I operate the button (pulldown to gnd) the LED and the published result stay off. returning to cycling upon release.
Thanks