LED Blinking Light - without delay
This example shows the simplest thing you can do with an Arduino board without any additional jumper wire to blink on-board LED.
The on-board LED on most Arduino boards is connected to a digital pin and pin number vary based board type. There is a "LED_BUILTIN" constant specified in every board descriptor file, the value of it is the pin number to which the on-board LED is connected and most boards have this LED connected to digital pin 13. This constant is and allows you to control the built-in LED easily.
/*
https://www.cheers2engineering.com/guided-projects/advanced-grades-9-12/arduino-advanced/arduino-blinking-light-without-delay
LED Blinking Light - without delay
ON Board LED - LED_BUILTIN
*/
// These variables store the flash pattern
// and the current state of the LED
int ledState = LOW; // ledState used to set the LED
unsigned long previousMilli = 0; // will store last time LED was updated
unsigned long currentMilli = 0;
long OnTime = 250; // on-time in millisecond
long OffTime = 500; // off-time in millisecond
// setup function - runs once when user press reset or power the board
void setup()
{
// initialize digital pin LED_BUILTIN as an output.
pinMode(LED_BUILTIN, OUTPUT);
}
// loop function runs over and over again
void loop()
{
currentMilli = millis();
// check previousMilli to see if it's time to change the state of the LED
if((ledState == HIGH) && (currentMilli - previousMilli >= OnTime))
{
ledState = LOW; // Turn LED off
previousMilli = currentMilli; // Remember the time
digitalWrite(LED_BUILTIN, ledState); // turn OFF the LED
}
else if ((ledState == LOW) && (currentMilli - previousMilli >= OffTime))
{
ledState = HIGH; // turn LED ON
previousMilli = currentMilli; // Remember the time
digitalWrite(LED_BUILTIN, ledState); // turn ON the LED
}
}