Wednesday, September 10, 2014

Raspberry Pi Python exercise: Toggle LED on GPIO

Python example run on Raspberry Pi, to toggle GPIO pin for LED.

connection:

Example code, led.py:
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
GPIO.setup(18, GPIO.OUT)
while(True):
 GPIO.output(18, True)
 time.sleep(1.5)
 GPIO.output(18, False)
 time.sleep(0.5)


Run it with sudo:
$ sudo python led.py

Next:
- Change GPIO LED brightness with GPIO.PWM

No comments:

Post a Comment

Subscribe to: Post Comments (Atom)

AltStyle によって変換されたページ (->オリジナル) /