LED
A small light source that lights up when electricity is applied.
Uses
A light-emitting diode (LED) is a small semiconductor diode which glows when a voltage is applied to it. In everyday life, you get to see LED in most standard lights. Some LEDs can be found as RGB LEDs, which means you can change the color of the LED to your liking.
In mechatronics, LEDs are often used as a simple display, notifying the user when a certain part of the code is running, e.g lighting up green when the program is ready. In the picture below you can see a simple LED setup with an .
Code examples
The example below shows how an LED in pin 11 is controlled.
const int LED = 11;
// the setup function runs once when you press reset or power the board
void setup() {
// initialize digital pin LED_BUILTIN as an output.
pinMode(LED, OUTPUT);
}
// the loop function runs over and over again forever
void loop() {
digitalWrite(LED, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(LED, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}