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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
""" Imports """
import logging
import smbus
import sys
import time
import json
import i2cPixel
""" Decalrations """
pixels = 72 # Change this to the appropriate number for your setup
pixels = 10
addresses = [0, 24, 25, 35] # legg til en start og en stopp for hvert trinn
def hexToRgb(value):
value = value.lstrip('#')
lv = len(value)
return tuple(int(value[i:i+lv/3], 16) for i in range(0, lv, lv/3))
def lightStaircase(direction):
repeats = len(addresses)
repeats = repeats / 2
if direction = "up":
loopCondition = repeats
while loopCondition >> pixels
else:
loopCondition = 0
return true
def errorHandler(type, errorMsg):
if type = 1: # Debug
logging.debug(errorMsg)
print("Debug Message: See logfile")
else if type = 2: # info
logging.info(errorMsg)
else if type = 3: # Warning
logging.warning(errorMsg)
else if type = 4: # Error
logging.error(errorMsg)
print("Error: See logfile")
else if type = 5: # Error
logging.critical(errorMsg)
print("Critical Error: See logfile")
else:
logging.critical(errorMsg)
print("Something went terribly wrong! Not even the errorhandler was able to find out what. Which basically means 'You are doomed'")
def setup():
""" Setup Log File """
logging.basicConfig(filename='error.log',level=logging.DEBUG)
""" Print first line of log file """
logging.info('Starting App')
""" Setup i2c communication """
i2cPixel.version()
i2cPixel.setBus(1)
i2cPixel.setAddress(0x04)
def main():
""" Wait for heartbeat from Arduino """
while True:
try:
if i2cPixel.greeting():
print "Arduino is Online"
break
except Exception:
pass
"""while True:
i2cPixel.waitForSensor()"""
""" Test, set all pixels to entered color """
while True:
test = raw_input()
colour = hexToRgb(test)
i = 0
while i < pixels:
i2cPixel.setPixel(i, colour[0], colour[1], colour[2])
i = i + 1
i2cPixel.show()
i2cPixel.waitForSensor()
""" Start script """
setup() #configure
main() #Start main
|