LED
An LED (light-emitting diode) lights up when current flows through it, but only in one direction. The long leg is + (anode), the short leg is − (cathode); the rim of the LED is also flat on the − side.
Long leg towards the pin, short leg towards GND, and always a resistor in the loop.
More: the loop, and the program
The loop
Current flows from the pin, through the resistor and the LED, into GND. When the program sets the pin to on (1, HIGH), the LED lights; off (0, LOW), and it is dark. Turned the wrong way round, nothing breaks, it just stays dark: turn it and try again.
Blink: on, wait, off, wait
The same in Python
def on_forever(): pins.digital_write_pin(DigitalPin.P1, 1) basic.pause(500) pins.digital_write_pin(DigitalPin.P1, 0) basic.pause(500) basic.forever(on_forever)
void setup() { pinMode(2, OUTPUT); // pin 2 is an output } void loop() { digitalWrite(2, HIGH); // on delay(500); digitalWrite(2, LOW); // off delay(500); }
Without the waits the LED would switch thousands of times a second, and you would only see a dim glow.