Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Kaarslicht simuleren met behulp van LED, PWM en Raspberry Pi
#!/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
You can’t perform that action at this time.