-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmetro_clock_gpio.py
58 lines (47 loc) · 1.19 KB
/
metro_clock_gpio.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
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
import time
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)
direction_file = "/home/metronaytto/projects/metro_display/direction.txt"
def move(direction):
GPIO.output(STBY, GPIO.HIGH) #disable standby
inPin1 = GPIO.LOW
inPin2 = GPIO.HIGH
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)
try:
file = open(direction_file, "r")
direction = file.read()
file.close()
if direction == "1":
move(1)
file = open(direction_file, "w")
file.write("0")
file.close()
else:
move(0)
file = open(direction_file, "w")
file.write("1")
file.close()
except Exception as e:
print(e)
finally:
GPIO.cleanup()