47
Step 2: Open the code file
cd
/
home
/
pi
/
SunFounder_Super_Kit_V3.0_for_Raspberry_Pi
/
Python
Step 3: Run
sudo
python
03_8Led.py
Code Explanation
LedPins = [17, 18, 27, 22, 23, 24, 25, 4]
# The cathodes of the 8 LEDs connect to B17,
B18, B27, 22, 23, 24, 25, 4 of the T-shape extension board. In BCM, these pins are
corresponding to 17, 18, 27, 22, 23, 24, 25, and 4.
leds = ['-', '-', '-', '-', '-', '-', '-', '-']
# the array to print out the status of
the 8 LEDs
for pin in LedPins
# Assign the element in pins list to pin variable one by one. In
GPIO.setup (pin, GPIO.OUT), set the pins in list as output one by one.
GPIO.output(pin, GPIO.LOW)
# Set each element in the pins list as low level to
light up the LEDs
leds[LedPins.index(pin)] = 0
# Show which LED is on
time.sleep(0.1)
# wait for 0.1s
GPIO.output(pin, GPIO.HIGH))
# After delaying, set it as high level to light up or
turn off the LED.
leds[LedPins.index(pin)] = '-'
# Show the led is off
You will see the eight LEDs lighten up one by one, and then dim in turn.
Содержание Super Kit 3.0
Страница 7: ...4 22 RGB LED 1 23 LED red 8 24 LED white 4 25 LED green 4 26 LED yellow 4 27 NPN Transistor S8050 2 ...
Страница 30: ...27 Also we have drawn a table of the corresponding BCM wiringPi and Name of each pins ...
Страница 78: ...75 Now pull the slide and you can see the two LEDs light up alternately ...