hi, im trying to make a timer and im using the millis()- function. The goal is that when the nappi = 1, the program runs the funktions and starts the timer. Btw the code is messed up and i just need a idea that how i make a timer (starts from 0) by using the millis()- function.
idea: button -> if(button == 1). Someone clicks it --> start the leds and the timer(1,2,3,4,5 s ...)
BlynkTimer timer;
int aika;
int button;
int aika2;
void setup()
{
pinMode(5, INPUT_PULLDOWN);
pinMode(0, OUTPUT);
Blynk.begin(auth, ssid, pass); //connects arduino to blynk wia internet
timer.setInterval(1000L, ajastin); //sends ajastin- function values to blynk every 1000 ms (every second)
aika2 = millis();
}
void loop()
{
button = digitalRead(5);
if(button == 1)
{
ledsekvenssi();
ajastin();
}
Blynk.run();
timer.run();
}
void ajastin()
{
Blynk.virtualWrite(V2, (millis() - aika) / 1000);
}
void ledsekvenssi()
{
digitalWrite(0, HIGH);
delay(500);
digitalWrite(0, LOW);
delay(500);
digitalWrite(0, HIGH);
delay(500);
digitalWrite(0, LOW);
delay(500);
digitalWrite(0, HIGH);
delay(500);
digitalWrite(0, LOW);
delay(500);
}