Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. import smbus
  2. import time
  3. from pad4pi import rpi_gpio
  4.  
  5. KEYPAD = [
  6. [1, 2, 3],
  7. [4, 5, 6],
  8. [7, 8, 9],
  9. ["*", 0, "#"]
  10. ]
  11.  
  12. ROW_PINS = [4, 14, 15, 17] # BCM numbering
  13. COL_PINS = [18, 27, 22] # BCM numbering
  14.  
  15. factory = rpi_gpio.KeypadFactory()
  16.  
  17. # Try factory.create_4_by_3_keypad
  18. # and factory.create_4_by_4_keypad for reasonable defaults
  19. keypad = factory.create_keypad(keypad=KEYPAD, row_pins=ROW_PINS, col_pins=COL_PINS)
  20.  
  21. def printKey(key):
  22. try:
  23. writeNumber(key)
  24. print('Wyslano do Arduino: ', key)
  25. number = readNumber()
  26. print('Potwierdzenie od Arduino, odebrano: ', number)
  27. print
  28. except:
  29. keypad.cleanup
  30.  
  31.  
  32.  
  33. keypad.registerKeyPressHandler(printKey)
  34.  
  35. # for RPI version 1, use "bus = smbus.SMBus(0)"
  36. bus = smbus.SMBus(1)
  37.  
  38. # This is the address we setup in the Arduino Program
  39. address = 0x04
  40.  
  41. def writeNumber(value):
  42. bus.write_byte(address, value)
  43. # bus.write_byte_data(address, 0, value)
  44. return -1
  45.  
  46. def readNumber():
  47. number = bus.read_byte(address)
  48. # number = bus.read_byte_data(address, 1)
  49. return number
  50.  
  51. while (True):
  52. time.sleep(0.2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement