Arduino timer - millis() - blynk

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);
}

Post your whole code, it doesn't show libraries included.
What board you have exactly? Not all have internal pulldowns.

aika doesn't have any value while aika2 has millis() from boot
You could just make a sketch to handle your counter and button and when you have it working, add blynk part to it.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.