Skip to content

Instantly share code, notes, and snippets.

@geniusmedia
Created December 18, 2017 11:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save geniusmedia/897bf6e2419ed7c40e3862c23fd7a4a3 to your computer and use it in GitHub Desktop.
Save geniusmedia/897bf6e2419ed7c40e3862c23fd7a4a3 to your computer and use it in GitHub Desktop.
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