From de76400657d7c5e164e2afcddc2f10728b9478e1 Mon Sep 17 00:00:00 2001 From: Jakob Stendahl Date: Fri, 23 Sep 2016 07:34:02 +0200 Subject: Update python.py --- Raspberry Pi/python.py | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) (limited to 'Raspberry Pi') diff --git a/Raspberry Pi/python.py b/Raspberry Pi/python.py index 9189f8e..71df0de 100644 --- a/Raspberry Pi/python.py +++ b/Raspberry Pi/python.py @@ -12,28 +12,37 @@ def hexToRgb(value): return tuple(int(value[i:i+lv/3], 16) for i in range(0, lv, lv/3)) def main(): - + """ Setup i2c communication """ i2cPixel.version() i2cPixel.setBus(1) i2cPixel.setAddress(0x04) - + """ 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: - test = raw_input() + """while True: + i2cPixel.waitForSensor()""" + + """ Test, set all pixels to entered color """ + while True: + test = raw_input() colour = hexToRgb(test) i = 0 while i < 10: i2cPixel.setPixel(i, colour[0], colour[1], colour[2]) i = i + 1 - i2cPixel.showPixel() - + i2cPixel.show() + i2cPixel.waitForSensor() + + """ Start script """ main() -- cgit v1.2.3 From 77ac60b5a29829bf8d2522d6cac0ce8120009b93 Mon Sep 17 00:00:00 2001 From: Jakob Stendahl Date: Fri, 23 Sep 2016 07:35:31 +0200 Subject: Update i2cPixel.py --- Raspberry Pi/i2cPixel.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'Raspberry Pi') diff --git a/Raspberry Pi/i2cPixel.py b/Raspberry Pi/i2cPixel.py index 6a53c02..788c771 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,26 @@ 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 waitForSensor(): - + while True: try: sensorData = bus.read_byte(arduinoAddress) - if sensorData = 0x02: - """ sjekk hvilken sensor """ - + if sensorData == 0x02: + print "SENSOR 1" + break; + if sensorData == 0x03: + print "SENSOR 2" + break; + except Exception: + pass -- cgit v1.2.3 From 968ffad2a6dfcab9e97372eff6e1070edb90cf19 Mon Sep 17 00:00:00 2001 From: Jakob Stendahl Date: Fri, 30 Sep 2016 10:22:48 +0200 Subject: Update i2cPixel.py [x] Added blink function [x] Added return on sensorfunction --- Raspberry Pi/i2cPixel.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'Raspberry Pi') diff --git a/Raspberry Pi/i2cPixel.py b/Raspberry Pi/i2cPixel.py index 788c771..936c828 100644 --- a/Raspberry Pi/i2cPixel.py +++ b/Raspberry Pi/i2cPixel.py @@ -34,6 +34,9 @@ def setPixel(n, red, green, blue): 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(): @@ -41,10 +44,12 @@ def waitForSensor(): try: sensorData = bus.read_byte(arduinoAddress) if sensorData == 0x02: - print "SENSOR 1" + print "Sensor 1 Triggered" + return 1 break; if sensorData == 0x03: - print "SENSOR 2" + print "Sensor 2 Triggered" + return 2 break; except Exception: pass -- cgit v1.2.3 From 175d4b91a2c53f67d6e4efa4fb2e62b753707d18 Mon Sep 17 00:00:00 2001 From: Jakob Stendahl Date: Sun, 2 Oct 2016 10:21:13 +0200 Subject: Update python.py Just a save --- Raspberry Pi/python.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'Raspberry Pi') diff --git a/Raspberry Pi/python.py b/Raspberry Pi/python.py index 71df0de..8ed3130 100644 --- a/Raspberry Pi/python.py +++ b/Raspberry Pi/python.py @@ -5,12 +5,26 @@ import i2cPixel """ Decalrations """ 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 main(): """ Setup i2c communication """ -- cgit v1.2.3