Advertisement
hackbyte

Simple Port Chaser for PCF8574 on I2C on Raspberry Pi REV1

Mar 5th, 2016
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.61 KB | None | 0 0
  1. #!/usr/bin/python
  2. from smbus import SMBus
  3. from itertools import cycle
  4. from time import sleep
  5.  
  6. IOEXTADDR = 0x38 # I2C adresse des PCF8574 IO Extenders
  7.  
  8. PAT0 = 0xff              # Alle Pins HIGH schaltet alle relais aus.
  9. PAT1 = int('11111110',2) # Relais 1 ein
  10. PAT2 = int('11111101',2) # Relais 2 ein
  11. PAT3 = int('11111011',2) # Relais 3 ein
  12. PAT4 = int('11110111',2) # Relais 4 ein
  13.  
  14. PATTERN = (PAT1,PAT2,PAT3,PAT4)
  15.  
  16. bus = SMBus(0) # I2C Port 0 auf REV 1 boards(!)
  17.  
  18. for DATABYTE in cycle(PATTERN):
  19.     bus.write_byte(IOEXTADDR, DATABYTE)
  20.     sleep(0.5)
  21.     bus.write_byte(IOEXTADDR, PAT0)
  22.     sleep(0.5)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement