aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob Stendahl <jakob@Jakobs-MacBook-Pro.local>2016-10-18 10:33:32 +0200
committerJakob Stendahl <jakob@Jakobs-MacBook-Pro.local>2016-10-18 10:33:32 +0200
commit44c8940211225e772851b36dc4088f3b6989f5f4 (patch)
tree639cb8f3d11eb858d11167876b4941d0db0f58c0
parent1fb2bdefd7627fde5a5adf594926ccc72d99fb19 (diff)
parent175d4b91a2c53f67d6e4efa4fb2e62b753707d18 (diff)
downloadi2c-Neopixel-44c8940211225e772851b36dc4088f3b6989f5f4.tar.gz
i2c-Neopixel-44c8940211225e772851b36dc4088f3b6989f5f4.zip
Merge remote-tracking branch 'origin/master'
# Conflicts: # Raspberry Pi/python.py
-rw-r--r--Raspberry Pi/i2cPixel.py24
-rw-r--r--Raspberry Pi/python.py37
2 files changed, 47 insertions, 14 deletions
diff --git a/Raspberry Pi/i2cPixel.py b/Raspberry Pi/i2cPixel.py
index 6a53c02..936c828 100644
--- a/Raspberry Pi/i2cPixel.py
+++ b/Raspberry Pi/i2cPixel.py
@@ -15,7 +15,7 @@ def setBus(n):
def greeting():
""" Send heartbeat """
bus.write_byte(arduinoAddress, 0x01)
-
+
""" Wait for response """
try:
response = bus.read_byte(arduinoAddress)
@@ -25,21 +25,31 @@ def greeting():
returnMsg = False
except:
returnMsg = False
- """ Return if heartbeat was received """
+ """ Return if heartbeat was received """
return returnMsg
def setPixel(n, red, green, blue):
""" Send values for switching a pixel on """
bus.write_block_data(arduinoAddress, 0x02, [n, red, green, blue])
-def showPixel():
+def show():
bus.write_byte(arduinoAddress, 0x03)
+
+def blink(time, red, green, blue):
+ bus.write_block_data(arduinoAddress, 0x04, [red, green, blue, time])
def waitForSensor():
-
+
while True:
try:
sensorData = bus.read_byte(arduinoAddress)
- if sensorData = 0x02:
- """ sjekk hvilken sensor """
-
+ if sensorData == 0x02:
+ print "Sensor 1 Triggered"
+ return 1
+ break;
+ if sensorData == 0x03:
+ print "Sensor 2 Triggered"
+ return 2
+ break;
+ except Exception:
+ pass
diff --git a/Raspberry Pi/python.py b/Raspberry Pi/python.py
index bdb939e..57cf380 100644
--- a/Raspberry Pi/python.py
+++ b/Raspberry Pi/python.py
@@ -7,15 +7,29 @@ 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():
- # Get settings from config.json
-
+
""" Setup i2c communication """
i2cPixel.version()
i2cPixel.setBus(1)
@@ -25,10 +39,17 @@ def main():
""" Wait for heartbeat from Arduino """
while True:
- if i2cPixel.greeting():
- print "Arduino is Online"
- break
+ 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)
@@ -37,9 +58,11 @@ def main():
while i < pixels:
i2cPixel.setPixel(i, colour[0], colour[1], colour[2])
i = i + 1
- i2cPixel.showPixel()
-
+ i2cPixel.show()
+ i2cPixel.waitForSensor()
+
+
""" Start script """
setup() #configure
main() #Start main