#!/usr/bin/env python3
# Import modules from the (built-in) standard library.
import time # Used to pause the script for a little while.
# Imports modules from related third party libraries.
# The RPi.GPIO library is included in 'Raspberry Pi OS with desktop'.
import RPi.GPIO as GPIO # Used to control the GPIO pins.
# Setup the GPIO channels.
GPIO.setmode(GPIO.BCM) # Set the pin numbering mode [^1]
led = 47 # Create a variable with the GPIO channel connected to the LED. [^2]
# The GPIO pin the green 'ACT' onboard LED is connected to.
GPIO.setup(led, GPIO.OUT) # Set the GPIO channel to be used as output.
try:
while True:
GPIO.output(led, GPIO.LOW) # Turn the LED on.
time.sleep(.25) # Wait for 0.25 seconds.
GPIO.output(led, GPIO.HIGH) # Turn the LED off.
time.sleep(.75) # Wait for 0.75 seconds.
except KeyboardInterrupt: # Control-C was pressed.
pass # Do nothing [^3].
# Turn the LED off.
GPIO.output(led, GPIO.LOW)
# Release the GPIO pins and set them to a safe state.
GPIO.cleanup()
print('\nBye, bye.')
"""
Wiring
------
The cathode of the green 'ACT' onboard LED near the microUSB 'PWR' connector is connected to 'GPIO47', the cathode with a 470R series resistor to 3V3. So the LED will be on if the value of the 'GPIO47' pin is set to 0 (= low).
References
----------
[^1]:
GPIO.BCM = GPIO channel numbers, GPIO.BOARD = header pin numbers
[^2]
Schematics of the Raspberry Pi Zero
https://www.raspberrypi.org/documentation/hardware/raspberrypi/schematics/RPI-ZERO-V1_3_reduced.pdf
On-Board-LEDs des Raspberry Pi steuern
https://kofler.info/on-board-leds-des-raspberry-pi-steuern/
[^3]:
'pass' is a Python specific keyword. It's required for otherwise
empty code blocks (= indented sequence of statements)
"""