Here is a snippet of code where I am trying to shutdown a neopixel stick so it goes off one led at a time. I want to be able to control the speed of the sequence with an interval. I can't seem to get the timer to work though. Looking for help.
/************************* Shutdown and helper functions ****************************/
unsigned long lastBarMillis_on = 0; // bargraph on tracker
const int pd_interval = 100; // interval at which to cycle lights (milliseconds).
void bargraph_shutdown(int currentMillis) {
if(currentMillis - lastBarMillis_on > pd_interval){
// save the last time you blinked the LED
lastBarMillis_on = currentMillis;
for (int i=7; i>-1; i-- ){//Bargraph power down sequence
barGraph.setPixelColor(i,0);
barGraph.show();}
safety=false;}}
Here is what I have, but still does not use the delay to shutdown each pixel:
/************************* Shutdown and helper functions ****************************/
// get the current time
unsigned long currentMillis = millis();
unsigned long lastBarMillis_on = 0; // bargraph on tracker
const int pd_interval = 100; // interval at which to cycle lights (milliseconds).
void bargraph_shutdown(unsigned long currentMillis) {
if(currentMillis - lastBarMillis_on > pd_interval){
// save the last time you blinked the LED
lastBarMillis_on = currentMillis;
for (int i=7; i>-1; i-- ){//Bargraph power down sequence
barGraph.setPixelColor(i,0);
barGraph.show();}
safety=false;}
}
In the code which you haven’t shown, is the function bargraph_shutdown() called once per shutdown, or is it called at regular intervals? In the function, there is no timing element in the loop which has the comment “ Bargraph power down sequence”, so it will go from 7 to 0 in a fraction of second.
Incidentally, it unusual to pass a value of millis() into a function. Instead, you can just test millis() directly in the function.
6v6gt:
In the code which you haven’t shown, is the function bargraph_shutdown() called once per shutdown, or is it called at regular intervals? In the function, there is no timing element in the loop which has the comment “ Bargraph power down sequence”, so it will go from 7 to 0 in a fraction of second.
Incidentally, it unusual to pass a value of millis() into a function. Instead, you can just test millis() directly in the function.
So, you expect the code to block until shutdown is complete. Given that, please explain why you are trying to convert it to a non-blocking function by not using delay().