Code to control onboard LEDs

The Pi comes with two LEDs on its board, for power and activity. It’s possible to control them via Python.

Note: not for Pi3.

To have the onboard LEDs blink, you can use code similar to this one:
print ("Program Start")
import RPi.GPIO as GPIO
import time

channels = [35, 47]
GPIO.setmode(GPIO.BCM)
GPIO.setup(channels, GPIO.OUT)
for i in range(5):
print (“Turning off LED’s”)
GPIO.output(channels, GPIO.LOW)
time.sleep(0.5)
print (“Turning on LED’s”)
GPIO.output(channels, GPIO.HIGH)
time.sleep(0.5)

GPIO.cleanup()

print (“Program End”)

Take note that the LEDs are still linked to their regular trigger. So if something else happens on the Pi, and the LED needs to display it (mainly the green one), then the blinking done here won’t be perfect.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s