LED Reference
Standard single-colour LED.
Pin names
| Name | Description |
|---|---|
| A | Anode (positive, longer leg) |
| C | Cathode (negative, shorter leg) |
Attributes
| Name | Description | Default |
|---|---|---|
| color | LED colour: "red", "green", "blue", "yellow", "white", "orange" | "red" |
Usage
Connect the A pin through a current-limiting resistor (220 Ω typical) to a GPIO pin, and the C pin to GND. Drive the GPIO HIGH to turn the LED on.
In real hardware always use a series resistor — omitting it will burn out the LED. The CNAP simulator does not enforce this but real circuits will.
const int LED_PIN = 13;
void setup() {
pinMode(LED_PIN, OUTPUT);
}
void loop() {
digitalWrite(LED_PIN, HIGH); // LED on
delay(500);
digitalWrite(LED_PIN, LOW); // LED off
delay(500);
}
Examples
| Description | Attrs |
|---|---|
| Default red | {} |
| Green LED | { "color": "green" } |
| Blue LED | { "color": "blue" } |
| Yellow LED | { "color": "yellow" } |
| White LED | { "color": "white" } |
See also
- Resistor — always pair an LED with a resistor
- RGB LED — three LEDs in one package with R, G, B, COM pins
- LED Bar Graph — 10-segment bar of LEDs in a single component