Created
December 18, 2017 11:29
-
-
Save geniusmedia/897bf6e2419ed7c40e3862c23fd7a4a3 to your computer and use it in GitHub Desktop.
Kaarslicht simuleren met behulp van LED, PWM en Raspberry Pi
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 python | |
# https://raspberrytips.nl/kaarslicht-pwm-raspberry-pi/ | |
import random, time | |
import RPi.GPIO as GPIO | |
led = 18 | |
GPIO.setmode(GPIO.BCM) | |
GPIO.setup(led, GPIO.OUT) | |
pwm = GPIO.PWM(led, 100) | |
RUNNING = True | |
def brightness(): | |
return random.randint(5, 100) | |
def flicker(): | |
return random.random() / 8 | |
print "Stop -> CTRL + C" | |
try: | |
while RUNNING: | |
pwm.start(0) | |
pwm.ChangeDutyCycle(brightness()) | |
time.sleep(flicker()) | |
except KeyboardInterrupt: | |
running = False | |
finally: | |
pwm.stop() | |
GPIO.cleanup() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment