Basic examples of Arduino programming
Cerințe pentru finalizare
Blink
There is no interfacing here since we are using Built In LED.
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
}
void loop() {
digitalWrite(LED_BUILTIN, HIGH);
delay(1000);
digitalWrite(LED_BUILTIN, LOW);
delay(1000);
This is a simple Arduino sketch that blinks the built-in LED on and off.
This code is also available on Pastebin: https://pastebin.com/5zrbYEY9
Code explanation:
- void setup()
is the setup function that runs only once when the Arduino board is powered on
or reset.
- pinMode(LED_BUILTIN, OUTPUT) sets the built-in LED pin as an output pin.
- void loop()
is the loop function that runs repeatedly after the setup function has
finished.
- digitalWrite(LED_BUILTIN, HIGH) turns the built-in LED on.
- delay(1000)
waits for 1000 milliseconds (1 second) before executing the next line of code.
- digitalWrite(LED_BUILTIN, LOW) turns the built-in LED off.
- delay(1000) waits for another 1000 milliseconds before repeating the loop and turning the LED on again.
This results in the built-in LED turning on for 1 second, turning off for 1 second, and repeating this cycle indefinitely.
