aboutsummaryrefslogtreecommitdiff
path: root/Raspberry Pi/i2cPixel.py
blob: 788c7712f0854ff004f938ee9d628155a41fed8d (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
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 show():
    bus.write_byte(arduinoAddress, 0x03)

def waitForSensor():

    while True:
        try:
            sensorData = bus.read_byte(arduinoAddress)
            if sensorData == 0x02:
                print "SENSOR 1"
                break;
            if sensorData == 0x03:
                print "SENSOR 2"
                break;
        except Exception:
            pass