aboutsummaryrefslogtreecommitdiffstats
path: root/python
diff options
context:
space:
mode:
authorgcohen2014-12-30 16:26:40 -0800
committergcohen2014-12-30 16:26:40 -0800
commit4a40d61925a8154e1939ddd24324761401bc876b (patch)
tree8ef57820594df1791cbf365338327f8d8957559f /python
parent2c35b50a351372e8d6f6ce4cb610f365e12d42dc (diff)
downloadpubnub-python-4a40d61925a8154e1939ddd24324761401bc876b.tar.bz2
refactored moveDoor()
Diffstat (limited to 'python')
-rw-r--r--python/examples/futureHouse/futureHouse.py80
-rw-r--r--python/examples/futureHouse/open.py1
2 files changed, 41 insertions, 40 deletions
diff --git a/python/examples/futureHouse/futureHouse.py b/python/examples/futureHouse/futureHouse.py
index ea25e81..4fbae3b 100644
--- a/python/examples/futureHouse/futureHouse.py
+++ b/python/examples/futureHouse/futureHouse.py
@@ -7,12 +7,17 @@ import Adafruit_BMP.BMP085 as BMP085
import Adafruit_DHT
import RPi.GPIO as GPIO
+# Initialize Humid / Temp
+
sensor = BMP085.BMP085()
+# Initialize Stepper
+
GPIO.setmode(GPIO.BOARD)
-StepPins = [26,24,22,19]
+stepPins = [26,24,22,19]
+waitTime = 0.000001
-for pin in StepPins:
+for pin in stepPins:
print "Setup pins"
GPIO.setup(pin,GPIO.OUT)
GPIO.output(pin, True)
@@ -106,47 +111,47 @@ pubnub.subscribe(channel, callback=callback, error=callback,
def moveDoor(direction):
- stepCount = 8
- globalcount = 1600
- cycles = 0
stepCounter = 0
- waitTime = 0.000001
-
- openSeq = range(0, stepCount)
- openSeq[0] = [1,0,0,0]
- openSeq[1] = [1,1,0,0]
- openSeq[2] = [0,1,0,0]
- openSeq[3] = [0,1,1,0]
- openSeq[4] = [0,0,1,0]
- openSeq[5] = [0,0,1,1]
- openSeq[6] = [0,0,0,1]
- openSeq[7] = [1,0,0,1]
-
- closeSeq = range(0, stepCount)
- closeSeq[7] = [1,0,0,0]
- closeSeq[6] = [1,1,0,0]
- closeSeq[5] = [0,1,0,0]
- closeSeq[4] = [0,1,1,0]
- closeSeq[3] = [0,0,1,0]
- closeSeq[2] = [0,0,1,1]
- closeSeq[1] = [0,0,0,1]
- closeSeq[0] = [1,0,0,1]
-
- # Choose a sequence to use
+ stepCount = 8
+
+ Seq = []
+ Seq = range(0, stepCount)
if direction == "open":
- seq = openSeq
+
+ Seq[0] = [1,0,0,0]
+ Seq[1] = [1,1,0,0]
+ Seq[2] = [0,1,0,0]
+ Seq[3] = [0,1,1,0]
+ Seq[4] = [0,0,1,0]
+ Seq[5] = [0,0,1,1]
+ Seq[6] = [0,0,0,1]
+ Seq[7] = [1,0,0,1]
+
elif direction == "close":
- seq = closeSeq
+
+ Seq[7] = [1,0,0,0]
+ Seq[6] = [1,1,0,0]
+ Seq[5] = [0,1,0,0]
+ Seq[4] = [0,1,1,0]
+ Seq[3] = [0,0,1,0]
+ Seq[2] = [0,0,1,1]
+ Seq[1] = [0,0,0,1]
+ Seq[0] = [1,0,0,1]
+
else:
return
+ maxSteps = 1600
+ completedSteps = 0
+
# Start main loop
- while 1==1:
+ while completedSteps != maxSteps:
+
for pin in range(0, 4):
- xpin = StepPins[pin]
+ xpin = stepPins[pin]
- pinVal = seq[stepCounter][pin]
+ pinVal = Seq[stepCounter][pin]
if pinVal!=0:
#print " Step %i Enable %i" %(StepCounter,xpin)
@@ -155,23 +160,18 @@ def moveDoor(direction):
GPIO.output(xpin, False)
stepCounter += 1
- cycles +=1
+ completedSteps +=1
print " Stepcounter: %i" %(stepCounter)
- # If we reach the end of the sequence
- # start again
if (stepCounter==stepCount):
stepCounter = 0
if (stepCounter<0):
stepCounter = stepCount
- if (globalcount == cycles):
- sys.exit()
-
- # Wait before moving on
time.sleep(waitTime)
+
# Initialise the PWM device using the default address
pwm = PWM(0x40, debug=False)
pwm.setPWMFreq(60) # Set frequency to 60 Hz
diff --git a/python/examples/futureHouse/open.py b/python/examples/futureHouse/open.py
index f6552bb..22cd948 100644
--- a/python/examples/futureHouse/open.py
+++ b/python/examples/futureHouse/open.py
@@ -16,6 +16,7 @@ stepCount = 8
Seq = []
Seq = range(0, stepCount)
+
Seq[0] = [1,0,0,0]
Seq[1] = [1,1,0,0]
Seq[2] = [0,1,0,0]