-
Notifications
You must be signed in to change notification settings - Fork 0
/
metro_clock_gpio_schedule.py
64 lines (49 loc) · 1.35 KB
/
metro_clock_gpio_schedule.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
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
import schedule
import time
import datetime
from threading import Event
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
STBY = 27 #Standby
PWM = 22 #Speed control
IN1 = 23 #Direction
IN2 = 24 #Direction
GPIO.setup(IN1, GPIO.OUT)
GPIO.setup(IN2, GPIO.OUT)
GPIO.setup(PWM, GPIO.OUT)
GPIO.setup(STBY, GPIO.OUT)
pwm_instance = GPIO.PWM(PWM, 1000)
exit = Event()
def move():
GPIO.output(STBY, GPIO.HIGH) #disable standby
inPin1 = GPIO.LOW
inPin2 = GPIO.HIGH
# Move to even minute with direction 0, to odd minute with direction 1
direction = datetime.datetime.now().minute % 2
if direction == 1:
inPin1 = GPIO.HIGH
inPin2 = GPIO.LOW
GPIO.output(IN1, inPin1)
GPIO.output(IN2, inPin2)
pwm_instance.start(100)
time.sleep(0.5)
pwm_instance.stop()
GPIO.output(STBY, GPIO.LOW) #enable standby
print("moved to direction: ", direction)
def main():
schedule.every().minute.at(':00').do(move)
while not exit.is_set():
schedule.run_pending()
time.sleep(.1)
print("All done!")
GPIO.cleanup()
def quit(signo, _frame):
print("Interrupted by %d, shutting down" % signo)
exit.set()
if __name__ == '__main__':
import signal
for sig in ('TERM', 'HUP', 'INT'):
signal.signal(getattr(signal, 'SIG'+sig), quit);
main()