Skip to content

Instantly share code, notes, and snippets.

@nezuppo
Last active September 19, 2018 13:37
Show Gist options
  • Save nezuppo/de74ace8da6db3a0ba5a9fafa6f0f156 to your computer and use it in GitHub Desktop.
Save nezuppo/de74ace8da6db3a0ba5a9fafa6f0f156 to your computer and use it in GitHub Desktop.
Raspberry Pi で LED の明るさコントロール
#!/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