Skip to content

Instantly share code, notes, and snippets.

@OmerShapira
Last active December 30, 2015 08:09
Show Gist options
  • Save OmerShapira/7800466 to your computer and use it in GitHub Desktop.
Save OmerShapira/7800466 to your computer and use it in GitHub Desktop.
PWM for Pi
import RPi.GPIO as GPIO
import threading
import time
class PWM(threading.Thread):
"""PWM Control"""
interval = 0.001
global pin_out
global normalized_avg
# Mapping
def __init__(self):
GPIO.setmode(GPIO.BCM)
GPIO.setup(pin_out, GPIO.OUT)
super(PWM, self).__init__()
def run(self):
while True:
GPIO.output(pin_out, GPIO.HIGH)
uptime = normalized_avg * self.interval
time.sleep(uptime)
GPIO.output(pin_out, GPIO.LOW)
time.sleep(self.interval-uptime)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment