aboutsummaryrefslogtreecommitdiff
path: root/Raspberry Pi
diff options
context:
space:
mode:
Diffstat (limited to 'Raspberry Pi')
-rw-r--r--Raspberry Pi/python copy.py45
-rw-r--r--Raspberry Pi/python.py39
2 files changed, 84 insertions, 0 deletions
diff --git a/Raspberry Pi/python copy.py b/Raspberry Pi/python copy.py
new file mode 100644
index 0000000..6a53c02
--- /dev/null
+++ b/Raspberry Pi/python copy.py
@@ -0,0 +1,45 @@
+import smbus
+import time
+
+def version():
+ print "i2cPixel is Version 1.0.0"
+
+def setAddress(address):
+ global arduinoAddress
+ arduinoAddress = address
+
+def setBus(n):
+ global bus
+ bus = smbus.SMBus(n)
+
+def greeting():
+ """ Send heartbeat """
+ bus.write_byte(arduinoAddress, 0x01)
+
+ """ Wait for response """
+ try:
+ response = bus.read_byte(arduinoAddress)
+ if response == 0x01:
+ returnMsg = True
+ else:
+ returnMsg = False
+ except:
+ returnMsg = False
+ """ 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():
+ bus.write_byte(arduinoAddress, 0x03)
+
+def waitForSensor():
+
+ while True:
+ try:
+ sensorData = bus.read_byte(arduinoAddress)
+ if sensorData = 0x02:
+ """ sjekk hvilken sensor """
+
diff --git a/Raspberry Pi/python.py b/Raspberry Pi/python.py
new file mode 100644
index 0000000..9189f8e
--- /dev/null
+++ b/Raspberry Pi/python.py
@@ -0,0 +1,39 @@
+""" Imports """
+import smbus
+import time
+import i2cPixel
+
+""" Decalrations """
+pixels = 10
+
+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 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
+
+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()
+
+
+""" Start script """
+main()