Codice: Seleziona tutto
import wiringpi2, smbus, sys, getopt, time, os, threading
from time import sleep
pin_base = 65
i2c_addr = 0x20
wiringpi2.wiringPiSetup()
wiringpi2.mcp23017Setup(pin_base,i2c_addr)
#uscite 65,66,67,68,69,70,71,72
wiringpi2.pinMode(65, 1)
wiringpi2.digitalWrite(65, 0)
#ingressi 80,81,82,83,84,85,86,87
wiringpi2.pinMode(80, 0)
wiringpi2.pullUpDnControl(80, 2)
# togliere il not per invertire il contatto
try:
while True:
if not wiringpi2.digitalRead(80):
wiringpi2.digitalWrite(65, 1)
else:
wiringpi2.digitalWrite(65, 0)
sleep(0.05)
finally:
wiringpi2.digitalWrite(65, 0)
wiringpi2.pinMode(65, 0)