Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import smbus
- import time
- from pad4pi import rpi_gpio
- KEYPAD = [
- [1, 2, 3],
- [4, 5, 6],
- [7, 8, 9],
- ["*", 0, "#"]
- ]
- ROW_PINS = [4, 14, 15, 17] # BCM numbering
- COL_PINS = [18, 27, 22] # BCM numbering
- factory = rpi_gpio.KeypadFactory()
- # Try factory.create_4_by_3_keypad
- # and factory.create_4_by_4_keypad for reasonable defaults
- keypad = factory.create_keypad(keypad=KEYPAD, row_pins=ROW_PINS, col_pins=COL_PINS)
- def printKey(key):
- try:
- writeNumber(key)
- print('Wyslano do Arduino: ', key)
- number = readNumber()
- print('Potwierdzenie od Arduino, odebrano: ', number)
- print
- except:
- keypad.cleanup
- keypad.registerKeyPressHandler(printKey)
- # for RPI version 1, use "bus = smbus.SMBus(0)"
- bus = smbus.SMBus(1)
- # This is the address we setup in the Arduino Program
- address = 0x04
- def writeNumber(value):
- bus.write_byte(address, value)
- # bus.write_byte_data(address, 0, value)
- return -1
- def readNumber():
- number = bus.read_byte(address)
- # number = bus.read_byte_data(address, 1)
- return number
- while (True):
- time.sleep(0.2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement