Skip to content

Instantly share code, notes, and snippets.

@pertoft
Created January 27, 2022 16:08
Show Gist options
  • Save pertoft/2669cc4787e81bbf691fae58c8ee1671 to your computer and use it in GitHub Desktop.
Save pertoft/2669cc4787e81bbf691fae58c8ee1671 to your computer and use it in GitHub Desktop.
Raspberry PI 4 PWM example
import RPi.GPIO as GPIO
from time import sleep
ledpin = 12 # PWM pin connected to LED
GPIO.setwarnings(False) #disable warnings
GPIO.setmode(GPIO.BOARD) #set pin numbering system
GPIO.setup(ledpin,GPIO.OUT)
pi_pwm = GPIO.PWM(ledpin,1000) #create PWM instance with frequency
pi_pwm.start(0) #start PWM of required Duty Cycle
pi_pwm.ChangeDutyCycle(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment