6. October 2018 20:46
by ĐÀO TƯỜNG SƠ
1 Comments
1. Linh kiện: giống dự án 01
2. Sơ đồ kết nối: giống dự án 01
3. Python Code: tạo file mới với tên led_brightness.py
import RPi.GPIO as GPIO
led_pin = 18
GPIO.setmode(GPIO.BCM)
GPIO.setup(led_pin, GPIO.OUT)
pwm_led = GPIO.PWM(led_pin, 500)
pwm_led.start(100)
while True:
duty_s = input("Enter Brightness (0 to 100): ")
duty = int(duty_s)
pwm_led.ChangeDutyCycle(duty)
4. Chạy chương trình:
sudo python led_brightness.py