Skip to content

Instantly share code, notes, and snippets.

@aslucki
Created March 28, 2021 15:39
Show Gist options
  • Save aslucki/d18cfe9be2687dec9a64c62d39931d24 to your computer and use it in GitHub Desktop.
Save aslucki/d18cfe9be2687dec9a64c62d39931d24 to your computer and use it in GitHub Desktop.
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BOARD)
GPIO.setup(33, GPIO.OUT)
# Setup 50Hz frequency PWM signal on the pin 33.
pwm = GPIO.PWM(33, 50)
pwm.start(0)
while True:
try:
duty_cycle = input("Set the duty cycle and press enter: ")
duty_cycle = float(duty_cycle)
print("The DC is:", duty_cycle)
pwm.ChangeDutyCycle(duty_cycle)
except KeyboardInterrupt:
break
pwm.stop()
GPIO.cleanup()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment