Hello to all team members. I tried to set delayed shutdown or delayed start using millis function.
Compiled, I couldn't run? I tried to adapt it to sample codes.
Can you share a small code blog? I would appreciate if you help me. It flashes like a flasher in all shared codes.
Why is the flasher used, does it turn on or off when the time expires with millis?
Anyone using reverse?
`unsigned long startMillis; //some global variables available anywhere in the program
unsigned long currentMillis;
const unsigned long period = 1000; //the value is a number of milliseconds
const byte ledPin = 13; //using the built in LED
void setup()
{
Serial.begin(115200); //start Serial in case we need to print debugging info
pinMode(ledPin, OUTPUT);
startMillis = millis(); //initial start time
}
void loop()
{
currentMillis = millis(); //get the current "time" (actually the number of milliseconds since the program started)
if (currentMillis - startMillis >= period) //test whether the period has elapsed
{
digitalWrite(ledPin, !digitalRead(ledPin)); //if so, change the state of the LED. Uses a neat trick to change the state
startMillis = currentMillis; //IMPORTANT to save the start time of the current LED state.
}
}
flasher millis output led
unsigned long startMillis; //some global variables available anywhere in the program
unsigned long currentMillis;
const unsigned long period = 1000; //the value is a number of milliseconds
const byte ledPin = 13; //using the built in LED
void setup()
{
Serial.begin(115200); //start Serial in case we need to print debugging info
pinMode(ledPin, OUTPUT);
startMillis = millis(); //initial start time
}
void loop()
{
currentMillis = millis();
if (currentMillis - startMillis >= period)
{digitalWrite(ledPin, HIGH); }
else
{digitalWrite(ledPin, LOW); }
startMillis = currentMillis;
}
Do you mean general start of your program working
Do you mean making your microcontroller not executing any code = "shutdown"
You can't shutdown a microcontroller like a computer. You would have to add hardware that switches off the power-supply
The more details you describe in your next posting what you really want to do the faster you will have a solution, because the less asking back for the left out details is nescessary
best regards Stefan
Because of this !digitalRead(ledPin) it toggles state every timeout.
If you want it to only make one action and never trigger again, add a condition to the if statement (and you don't need to remember when you turned it off):
if (digitalRead(ledPin) == HIGH && currentMillis - startMillis >= period) //test whether the period has elapsed
{
digitalWrite(ledPin, LOW); // turn it off
// startMillis = currentMillis; //not IMPORTANT to save the start time of the current LED state.
}