Ticker

6/recent/ticker-posts

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

إرسال تعليق

0 تعليقات