diff options
| author | gcohen | 2014-12-29 19:05:52 -0800 | 
|---|---|---|
| committer | gcohen | 2014-12-29 19:05:52 -0800 | 
| commit | 1ec3be5b1506d5ff48319bf55012e2fea9b4be0b (patch) | |
| tree | 145d2e7117ac77960af607531e1a0e2374c0bb08 | |
| parent | 0da436b0a940690b1fa1af1951b8ca1d1e94fff3 (diff) | |
| download | pubnub-python-1ec3be5b1506d5ff48319bf55012e2fea9b4be0b.tar.bz2 | |
wip
| -rw-r--r-- | python/examples/futureHouse/futureHouse.py | 33 | 
1 files changed, 32 insertions, 1 deletions
| diff --git a/python/examples/futureHouse/futureHouse.py b/python/examples/futureHouse/futureHouse.py index 87a6e6d..9ff8a99 100644 --- a/python/examples/futureHouse/futureHouse.py +++ b/python/examples/futureHouse/futureHouse.py @@ -1,5 +1,8 @@  import sys  from Pubnub import Pubnub +from Adafruit_PWM_Servo_Driver import PWM +import time +import random  publish_key = len(sys.argv) > 1 and sys.argv[1] or 'demo-36'  subscribe_key = len(sys.argv) > 2 and sys.argv[2] or 'demo-36' @@ -37,5 +40,33 @@ def disconnect(message):      print("DISCONNECTED") + +# http://www.raspberrypi.org/forums/viewtopic.php?f=37&t=32826 + +# Initialise the PWM device using the default address +pwm = PWM(0x40, debug=False) + +ledMin = 150  # Min pulse length out of 4096 +ledMax = 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,6) : +        # Change speed of continuous servo on channel O +        pwm.setPWM(x, 0, ledMin) +        time.sleep(random.uniform(0.005,0.0001)) +        pwm.setPWM(x, 0, ledMax) +        time.sleep(random.uniform(0.005,0.0001)) +  pubnub.subscribe(channel, callback=callback, error=callback, -                 connect=connect, reconnect=reconnect, disconnect=disconnect)
\ No newline at end of file +                 connect=connect, reconnect=reconnect, disconnect=disconnect) | 
