diff options
| author | geremy@pubnub.com | 2014-12-26 00:44:06 -0800 |
|---|---|---|
| committer | geremy@pubnub.com | 2014-12-26 00:44:06 -0800 |
| commit | c2a3ee12ce2c42b05e1ee31d737d9a8703f4a580 (patch) | |
| tree | e7b0f69ca6473cabeaff12e9b4b08d0eda23b035 /python/examples/pnPWM/Servo_Example.py | |
| parent | 6cf7b3a5941416377035772dd16c77fd621796c0 (diff) | |
| download | pubnub-python-c2a3ee12ce2c42b05e1ee31d737d9a8703f4a580.tar.bz2 | |
adding pwm sample
Diffstat (limited to 'python/examples/pnPWM/Servo_Example.py')
| -rw-r--r-- | python/examples/pnPWM/Servo_Example.py | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/python/examples/pnPWM/Servo_Example.py b/python/examples/pnPWM/Servo_Example.py new file mode 100644 index 0000000..c5ca88a --- /dev/null +++ b/python/examples/pnPWM/Servo_Example.py @@ -0,0 +1,38 @@ +#!/usr/bin/python + +from Adafruit_PWM_Servo_Driver import PWM +import time + +# =========================================================================== +# Example Code +# =========================================================================== + +# Initialise the PWM device using the default address +pwm = PWM(0x40, debug=True) +# Note if you'd like more debug output you can instead run: +#pwm = PWM(0x40, debug=True) + +servoMin = 150 # Min pulse length out of 4096 +servoMax = 600 # Max pulse length out of 4096 + +def setServoPulse(channel, pulse): + pulseLength = 1000000 # 1,000,000 us per second + pulseLength /= 60 # 60 Hz + print "%d us per period" % pulseLength + pulseLength /= 4096 # 12 bits of resolution + print "%d us per bit" % pulseLength + pulse *= 1000 + pulse /= pulseLength + pwm.setPWM(channel, 0, pulse) + +pwm.setPWMFreq(60) # Set frequency to 60 Hz +while (True): + for x in range(0,15) : + # Change speed of continuous servo on channel O + pwm.setPWM(x, x, servoMin) + time.sleep(0.0001) + pwm.setPWM(x, x, servoMax) + time.sleep(0.0001) + + + |
