Last active
December 30, 2015 08:09
-
-
Save OmerShapira/7800466 to your computer and use it in GitHub Desktop.
PWM for Pi
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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