Advertisement
Guest User

Untitled

a guest
Aug 2nd, 2015
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.73 KB | None | 0 0
  1. #!/usr/bin/python
  2.  
  3. import smbus
  4. import time
  5. import os
  6.  
  7. bus = smbus.SMBus(1)
  8. adr = 0x22
  9.  
  10. def readButtons():
  11.         try:
  12.                 res = bus.read_i2c_block_data( adr, 0xFF, 3 );
  13.  
  14.                 a = res[0]
  15.                 b = res[1]
  16.                 c = res[2]
  17.  
  18.                 return (a * 255 + b), c
  19.         except:
  20.                 return 0,0
  21.  
  22. a, c = readButtons()
  23. print bin(c),1
  24. a, c = readButtons()
  25. print bin(c),2
  26.  
  27. b = 31
  28. print bin(c), ' binary value c'
  29. print bin(b), ' binary value b'
  30.  
  31. while 1:
  32.         a, c = readButtons()
  33.         print bin(c), ' binary value c'
  34.         print bin(b), ' binary value b'
  35.         if ((c & 1) != (b & 1)):
  36.                 b = c
  37.                 print bin(c & 1), ' test1'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement