Hi community,
I might have a question for you. It's actually about a very simple push button circuit. Only 2 push buttons are installed. One should switch on the LED (NeoPixel) array via the while loop. The other button should deactivate the while loop. Unfortunately, the code doesn't work. Without even pressing the on button, the while loop already starts. When I press the off button, I interrupt the LED only for the duration of the delay of button 2 (see status2, delay 500 ms). Can you find the issue?
#include <Adafruit_NeoPixel.h>
int Pin = 8;
int On = 7;
int Off = 4;
int Leds = 7; // No. of LEDs
int r = 255;
int g = 255;
int b = 255;
int status1 = 0;
int status2 = 0;
boolean k = false;
//NeoPixel initialize
Adafruit_NeoPixel NeoPixel(Leds, Pin, NEO_GRB + NEO_KHZ800);
void setup() {
pinMode(Pin, OUTPUT);
pinMode(On, INPUT);
pinMode(Off, INPUT);
NeoPixel.begin();
}
void loop() {
status1 = digitalRead(On);
if(status1 == HIGH)
{
boolean k = true;
delay(50);
}
while(k = true) {
status2 = digitalRead(Off);
if(status2 == HIGH) {
boolean k = false;
NeoPixel.setPixelColor(0, NeoPixel.Color(0, 0, 0));
NeoPixel.show();
delay(500);
}
//Preamble
NeoPixel.setPixelColor(0, NeoPixel.Color(r, g, b));
NeoPixel.show();
delay(10);
}
}