-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcombined.py
65 lines (54 loc) · 1.87 KB
/
combined.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
65
import time
import datetime
import smbus
import RPi.GPIO as GPIO
from BerryImu import BerryImu
from squid import *
clk = 17
dt = 18
GPIO.setmode(GPIO.BCM)
GPIO.setup(clk, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(dt, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(clk, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(dt, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
clkLastState = GPIO.input(clk)
bus = smbus.SMBus(1)
imu = BerryImu(bus)
imu.initialise()
rgb = Squid(18, 23, 24)
try:
while True:
clkState = GPIO.input(clk)
dtState = GPIO.input(dt)
if clkState != clkLastState:
if dtState != clkState:
if counter <= 2:
counter += 1
else:
counter = 3
else:
if counter!=0:
counter -= 1
else:
counter=0
if counter==0:
camera.zoom = (0, 0, 1.0, 1.0)
if counter==1:
camera.zoom = (0.25, 0.25, 0.5, 0.5)
if counter==2:
camera.zoom = (0.125, 0.125, 0.5, 0.5)
if counter==3:
camera.zoom = (0.0625, 0.0625, 0.5, 0.5)
clkLastState = clkState
gyr_meas = imu.read_gyr_data()
time.sleep(0.25)
gyr_meas2 = imu.read_gyr_data()
value = abs(gyr_meas[1] - gyr_meas2[1])
if (value <= 2):
rgb.set_color(GREEN)
elif(value <= 12):
rgb.set_color(YELLOW)
elif(value > 12):
rgb.set_color(RED)
finally:
GPIO.cleanup()