Alternating flasher on the Raspberry Pi
FunduinoPublished on
Zwei LEDs abwechselnd blinken lassen – mit Python und gpiozero
You need this
830-point Breadboard - solderless breadboard for Arduino
2,90 € *Item no. FUN-1010553About the product — 830-point Breadboard - solderless breadboard for Arduino
Breadboard Cables Male-to-Male - 40 Pieces, 20 cm
1,74 € *Item no. FUN-1010558About the product — Breadboard Cables Male-to-Male - 40 Pieces, 20 cm
LED 5 mm - 100 Pieces, 5 Colors, 2 V
1,97 € *Item no. F23107316About the product — LED 5 mm - 100 Pieces, 5 Colors, 2 V
Resistor Assortment 100 Pieces - 5 Values 100 Ω to 10 kΩ, 0.5 W
1,72 € *Item no. F23107216About the product — Resistor Assortment 100 Pieces - 5 Values 100 Ω to 10 kΩ, 0.5 W
All 4 parts together 8,33 € *Ready to ship immediately · Delivery time: 1-3 business days
* All prices include statutory VAT, plus shipping costs.
Connect the LEDs
The program
alternating-blinker.py
# Import the library for the LEDs
from gpiozero import LED
from time import sleep
LED1 = LED(23) # the first LED is connected to GPIO 23 (Pin 16)
LED2 = LED(24) # the second LED is connected to GPIO 24 (Pin 18)
while True: # the main program runs forever
LED1.on() # turn on the first LED
LED2.off() # turn off the second LED
sleep(1) # wait 1 second
LED1.off() # turn off the first LED
LED2.on() # turn on the second LED
sleep(1) # wait 1 second
# the program then jumps back to the beginning of the loopRate the instructions