Esempio n. 1
0

def repeat(interval, func):
    def loop():
        while not Event().wait(interval):
            func()

    Thread(target=loop).start()


# uses https://raw.githubusercontent.com/tomstokes/python-spi/master/spi.py
from spi import SPI

spi = SPI('/dev/spidev1.0')
spi.mode = SPI.MODE_0
spi.bits_per_word = 8
spi.speed = 10 * 1000000

IODIRA = 0x00
IOCON = 0x0a
GPIOA = 0x12


# write to MCP23S17 register(s), GPIOA by default
def mcp23s17(address, values, register=GPIOA):
    global spi
    opcode = 0x40 | (address << 1)
    spi.write([opcode, register] + values)


# configure up to 5 MCP23S17