Red and Green LED lights
LED stands for Light Emitting Diode, and glows when electricity is passed through it.
The LED has one leg is longer than the other. The longer leg (known as the ‘anode’), is always connected to the positive supply of the circuit. The shorter leg (known as the ‘cathode’) is connected to the negative side of the power supply, known as ‘ground’. LEDs will only work if power is supplied the correct way round (i.e. if the ‘polarity’ is correct).
The Raspberry Pi's GPIO Pins
GPIO stands for General Purpose Input Output. It is a way the Raspberry Pi can control and monitor the outside world by being connected to electronic circuits. The Raspberry Pi is able to control LEDs, turning them on or off, or motors, or many other things. It is also able to detect whether a switch has been pressed, or temperature, or light. In the CamJam EduKit you will learn to control LEDs and a buzzer, and detect when a button has been pressed.
In the Schematics it is directly connected to Pin 7 of the 40 Pin Connector. This corresponds to the GPIO4 Pin.
This is the location of the Green LED on the board.
Following python code can be used to turn the LED on or off.
1 2 3 4 5 6 7 8 9 10
import RPi.GPIO as GPIO import time GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) GPIO.setup(4,GPIO.OUT) print "LED on" GPIO.output(4,GPIO.HIGH) time.sleep(1) print "LED off" GPIO.output(18,GPIO.LOW)
Exercise 1 – Turn on Red LED in place of Green LED
Exercise 2 - Turn Green and Red LED ON off Alternatively
Exercise 3 - Turn Green and Red LED ON off Alternatively