led.py
import RPi.GPIO as GPIO
import time
led_pin = 18
GPIO.setmode(GPIO.BCM)
GPIO.setup(led_pin, GPIO.OUT)
#frequency 500 Hz
led_pwm = GPIO.PWM(led_pin, 500)
#duty cycle = 100
led_pwm.start(100)
while(True):
led_pwm.ChangeDutyCycle(100)
time.sleep(1)
led_pwm.ChangeDutyCycle(80)
time.sleep(1)
led_pwm.ChangeDutyCycle(60)
time.sleep(1)
led_pwm.ChangeDutyCycle(40)
time.sleep(1)
led_pwm.ChangeDutyCycle(20)
time.sleep(1)
led_pwm.ChangeDutyCycle(0)
time.sleep(1)
Connection, check lst post of "Toggle LED on GPIO".
No comments:
Post a Comment