Millis() Function with Nerdonic Exen Mini

Description: Using a simple millis() function to blink an LED once every second, instead of the delay() function which is a blocking code.

Millis() Function with Nerdonic Exen Mini

Supplies:

1 –  Breadboard 400 Points
1 – Nerdonic Exen Mini
1 – LED
1 – 220 Ohm Resistor

Arduino Code:

#define led A4

int led_state = LOW;

unsigned long prevTime = millis();

void setup() {

  pinMode(led, OUTPUT);

}

void loop() {

  unsigned long currentTime = millis();

  if(currentTime - prevTime > 1000) {
    led_state = !led_state;
    digitalWrite(led, led_state);
    prevTime = currentTime;
  }
}

Leave a Comment

12 + = 13