forked from tpaulus/7-Seg-MCP3008
-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.py
64 lines (56 loc) · 1.42 KB
/
App.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
#! /usr/bin/python
#Written By Tom Paulus, @tompaulus, www.tompaulus.com
from Adafruit_LEDBackpack.Adafruit_7Segment import SevenSegment
from Ard import *
green = 25
yellow = 24
red = 23
mosfet = 18
led1 = 4
led2 = 22
led3 = 21
pot_adc = 7
light_adc = 6
mode = 0
l = list()
segment = SevenSegment(address=0x70) #which port the display is
A = Arduino("BCM") #define the port name style
print "Press CTRL+Z to exit"
#Set the port types
A.pinMode(green,'IN')
A.pinMode(yellow,'IN')
A.pinMode(red,'IN')
A.pinMode(led1,'OUT')
A.pinMode(led2,'OUT')
A.pinMode(led3,'OUT')
#Turn off all LEDs
A.digitalWrite(led1,"LOW")
A.digitalWrite(led2,"LOW")
A.digitalWrite(led3,"LOW")
while True:
A.digitalWrite(led1,"HIGH")
pot = A.analogRead(pot_adc)
light = A.analogRead(light_adc)
lightAvg = A.movavg(l,4,light)
if A.digitalRead(green):
mode = 0
elif A.digitalRead(yellow):
mode = 1
elif A.digitalRead(red):
A.digitalWrite(led1,"LOW")
A.digitalWrite(led2,"LOW")
A.digitalWrite(led3,"LOW")
print 'App Terminated by RED BUTTON!'
segment.writeInt(0000)
break
if not mode:
A.digitalWrite(led2,"HIGH")
A.digitalWrite(led3,"LOW")
segment.writeInt(pot)
elif mode:
A.digitalWrite(led2,"LOW")
A.digitalWrite(led3,"HIGH")
segment.writeInt(lightAvg)
time.sleep(.125)
A.digitalWrite(led1,"LOW")
time.sleep(.175)