Skip to content

Commit

Permalink
Set up PWM support
Browse files Browse the repository at this point in the history
Right now we are defining the arguments in terms of the frequency
and the duty cycle. On the Edison this is technically the period
and duty cycle, but the Raspberry Pi doesn't actually match the
frequency properly anyway.

These two parameters will need to be standardized in the near
future across Zorg adaptors, so the argument names can line up
and requests to the API can function properly.
  • Loading branch information
kevin-brown committed Jul 16, 2015
1 parent cac1790 commit 97af53a
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions zorg_raspi/adaptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,21 @@ def __init__(self, options):

GPIO.setmode(GPIO.BOARD)

self.pwm = {}

def digital_write(self, pin_number, value):
GPIO.setup(pin_number, GPIO.OUT)

GPIO.output(pin_number, value)

def pwm_write(self, pin_number, duty_cycle, frequency):
if pin_number not in self.pwm:
GPIO.setup(pin_number, GPIO.OUT)

self.pwm[pin_number] = GPIO.PWM(pin_number, frequency)
self.pwm[pin_number].start(duty_cycle)

pin = self.pwm[pin_number]

pin.ChangeFrequency(frequency)
pin.ChangeDutyCycle(duty_cycle)

0 comments on commit 97af53a

Please sign in to comment.