Hi, not too long ago when I started Arduino fun, and I have a problem here. Maybe somebody can help me. Idea is, when button pressed, it shows what is temperature range .Everything is running well, but lights are staying on after button is released. Feel free to point on my other mistakes also.
Sorry for my English!
You're not turning them off if the button is not pressed.
if (buttonState == HIGH) {
// setPixelColor depending on value of T
} else {
strip.setPixelColor(0, 0, 0, 0); // all off, presumably?
}
strip.show(); // executes regardless of buttonState
Thank you!
Missing strip.show(); after strip.setPixelColor(0, 0, 0, 0); was my problem. I tried before with strip.setPixelColor(0, 0, 0, 0);, but without strip.show(); , now I know why it did not worked!
If you have a little bit time, can you, please, check, what would you do better if you made my code?
I like to move "top-down" programming into functions. I like to use setup() to prepare LEDs and buttons (any sensor). Then I like to use loop() to call any function (sensors, button, time, calculations, decisions). When I have a new idea, I can make another separate function and add a call to the new function from loop() without re-write the core code. The compiler does the work to put events in logical, efficient order. Here is a simulation with a small example...