Ejemplo n.º 1
0
      if (DI[i] != DI_new[i]):
        #If old doesn't match new value... that PIN changed
        print("PIN "+str(i)+" changed")
    #print out a list of the current state of all inputs
    for i in range(0,7):    
      sys.stdout.write(str(DI[i]))
      sys.stdout.write(" ")
    print("")
    print("")
    #Don't forget that step... new=old
    DI=DI_new
      
    
    
    
    
# Setup the GPIO
GPIO.setmode(GPIO.BCM)  
GPIO.setup(INT_GPIO, GPIO.IN)  
# Add Interrupt on GPIO 4 on FALLING edge. 
# Be aware that the bouncetime may need to change in our environment.
GPIO.add_event_detect(INT_GPIO, GPIO.RISING, callback = Interrupt, bouncetime = 200)   
print ("Interrupt handler set... waiting")
print (i2ciotools.readDigitalInput(I2C_PORT, DI_MODULE_1_ADDR))
    
while True:
  print (".")
  time.sleep(100)
        

Ejemplo n.º 2
0
try: 
  #Set the output PIN/Port 1 to 0 (inactive)
  #Use the slightly different writeDigitalOutputPort to do that...
  i2ciotools.writeDigitalOutputPort(I2C_PORT, DO_MODULE_1_ADDR, 1, 0)

  #Read using the readDigitalInputPort 
  if (i2ciotools.readDigitalInputPort(I2C_PORT, DI_MODULE_1_ADDR,1)==1):
    print ("Input is active")
  else:
    print ("Input is NOT active")

  #Let's go hardcore and send the byte directly (note the negated byte)  
  #Set the output PIN/Port 1 to 1 (active)   
  i2ciotools.writeDigitalOutput(I2C_PORT, DO_MODULE_1_ADDR, 0xFE)

  if (i2ciotools.readDigitalInput(I2C_PORT, DI_MODULE_1_ADDR)==0xFE):
    print ("Input is active")
  else:
    print ("Input is NOT active")
  
  #Set the output PIN/Port 1 to 0 (inactive)
  #Back to the shortest notation...
  i2ciotools.writeDigitalOutputSimple(EXAMPLE_DIGITAL_OUTPUT, 0)

  if (i2ciotools.readDigitalInputSimple(EXAMPLE_DIGITAL_INPUT)==0xfe):
    print ("Input is active")
  else:
    print ("Input is NOT active")
  
except:
  print ("ERROR! DI and DO... you really should check the addresses of these modules and if you wired them correctly")