import wiringpi
from time import sleep

base = 65
i2c = 0x20

timer = .5

wiringpi.wiringPiSetupGpio()
wiringpi.mcp23017Setup(base, i2c)


for i in range(base, base+16):
  wiringpi.pinMode(i, 1)

wiringpi.digitalWrite(base+8, 0)
wiringpi.digitalWrite(base+9, 0)

def data(value):
  wiringpi.digitalWrite(base+3, value)
  
def select_mux(mux):
  wiringpi.digitalWrite(base+8, not mux)
  wiringpi.digitalWrite(base+8 + 1, mux)

def select_latch(A,B,C):
  wiringpi.digitalWrite(base + 5, A)
  wiringpi.digitalWrite(base + 6, B)
  wiringpi.digitalWrite(base + 7, C)

def select_latch_pin(A0,A1,A2):
  wiringpi.digitalWrite(base, A0)
  wiringpi.digitalWrite(base +1, A1)
  wiringpi.digitalWrite(base+2, A2)

def trigger_pin(lA, lB, lC, A0, A1, A2):
  select_latch(lA, lB, lC)
  select_latch_pin(A0,A1,A2)
  data(1)
  sleep(timer)
  data(0)
