Last active
September 19, 2018 13:37
-
-
Save nezuppo/de74ace8da6db3a0ba5a9fafa6f0f156 to your computer and use it in GitHub Desktop.
Raspberry Pi で LED の明るさコントロール
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
''' root 権限が無いとシステムがフリーズします ''' | |
import wiringpi | |
import time | |
PWM_PIN = 18 | |
STEP = 32 | |
SLEEP_TIME = 0.05 | |
wiringpi.wiringPiSetupGpio() | |
wiringpi.pinMode(PWM_PIN, wiringpi.GPIO.PWM_OUTPUT) | |
while True: | |
for i in range(0, 1024, STEP): | |
wiringpi.pwmWrite(PWM_PIN, i) | |
time.sleep(SLEEP_TIME) | |
for i in range(1024, 0, STEP * -1): | |
wiringpi.pwmWrite(PWM_PIN, i) | |
time.sleep(SLEEP_TIME) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment