-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadafruitIOStepper.py
53 lines (42 loc) · 1.24 KB
/
adafruitIOStepper.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import time
from Adafruit_IO import *
import RPi.GPIO as GPIO
pin = 2 # Our LED is on GPIO pin 2
direction = 4
step = 3
with open('key.txt') as f:
key = f.readline() # Load key from separate file - first line of key.txt
key = key.strip('\n') # Remove newline character from key
while True:
client = Client(key)
if int(client.receive('OnOff').value):
client.send('OnOff', 0)
# Light up LED
GPIO.setmode(GPIO.BCM) # BCM for GPIO numbering
GPIO.setwarnings(False) # Disable warnings
GPIO.setup(pin, GPIO.OUT)
for x in range(0,1):
GPIO.output(pin, True)
time.sleep(1)
GPIO.output(pin, False)
time.sleep(1)
# Setup
GPIO.setup(direction, GPIO.OUT)
GPIO.setup(step, GPIO.OUT)
GPIO.output(direction, True)
for x in range(0, 1000):
# Turn Stepper Motor
GPIO.output(step, False)
time.sleep(0.0001)
GPIO.output(step, True)
time.sleep(0.0001)
GPIO.output(direction, False)
for x in range(0, 500):
# Turn Stepper Motor
GPIO.output(step, False)
time.sleep(0.0001)
GPIO.output(step, True)
time.sleep(0.0001)
# Cleanup
GPIO.cleanup()
time.sleep(1)