aboutsummaryrefslogtreecommitdiff
path: root/Raspberry Pi/python.py
blob: 57cf38053e73ea61c5d9c5398d87dd2fbafc81b9 (plain) (blame)
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
""" Imports """
import logging
import smbus
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 setup():

    """ 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