예제 #1
0
 def initlize_keypad(self):
     """
         initlizing 4x4 pi keypad
     """
     log("Initlization of keypad starts in initlize keypad method")
     row_pins = [board.D21, board.D20, board.D16, board.D12]
     log(f"row_pins are {row_pins}")
     col_pins = [board.D26, board.D19, board.D13, board.D6]
     log(f"col_pins are {col_pins}")
     self.rows = []
     self.cols = []
     log(f"cols = {self.cols} and rows = {self.rows}")
     for row_pin in row_pins:
         self.rows.append(digitalio.DigitalInOut(row_pin))
     log(f"after initlizing i/o pins rows = {self.rows}")
     for col_pin in col_pins:
         self.cols.append(digitalio.DigitalInOut(col_pin))
     log(f"after initlizing i/o pins cols = {self.cols}")
     log("Defining Keypad Layout")
     self.keys = (("D", "#", 0, "*"), ("C", 9, 8, 7), ("B", 6, 5, 4),
                  ("A", 3, 2, 1))
     log(f"keypad is \n{self.keys}")
     self.keypad = adafruit_matrixkeypad.Matrix_Keypad(
         self.rows, self.cols, self.keys)
     log(f"matrix keypad now is {self.keypad}")
     print("Intilization of keypad is sucessfull")
     return self.keypad
예제 #2
0
    def __init__(self, rotation=0):
        self._rotation = rotation
        self.pixels = _NeoPixelArray(board.NEOPIXEL,
                                     width=8,
                                     height=4,
                                     rotation=rotation)

        print(dir(board))
        cols = []
        for x in range(8):
            d = digitalio.DigitalInOut(getattr(board, "COL{}".format(x)))
            cols.append(d)

        rows = []
        for y in range(4):
            d = digitalio.DigitalInOut(getattr(board, "ROW{}".format(y)))
            rows.append(d)

        key_names = []
        for y in range(8):
            row = []
            for x in range(4):
                if rotation == 0:
                    coord = (x, y)
                elif rotation == 180:
                    coord = (3 - x, 7 - y)
                elif rotation == 90:
                    coord = (3 - x, y)
                elif rotation == 270:
                    coord = (x, 7 - y)
                row.append(coord)
            key_names.append(row)

        self._matrix = adafruit_matrixkeypad.Matrix_Keypad(
            cols, rows, key_names)
예제 #3
0
def test_keypad():
    # 4x4 matrix keypad
    rows = [
        DigitalInOut(x) for x in (board.D4, board.D17, board.D27, board.D22)
    ]
    cols = [
        DigitalInOut(x) for x in (board.D18, board.D23, board.D24, board.D25)
    ]
    keys = (('1', '2', '3', 'A'), ('4', '5', '6', 'B'), ('7', '8', '9', 'C'),
            ('*', '0', '#', 'D'))

    keypad = adafruit_matrixkeypad.Matrix_Keypad(rows, cols, keys)

    print('Press 1234A')
    entered_keys = ''
    while True:
        keys = keypad.pressed_keys
        if keys:
            if keys[0] == '*':
                print('Done')
                return entered_keys == '1234A'
            elif keys[0] == 'C':
                entered_keys = ''
            else:
                entered_keys += keys[0]
            print("Pressed: ", entered_keys)
            sleep(0.2)
 def listenKeypad(self):
     cols = [digitalio.DigitalInOut(x)
             for x in (board.D13, board.D6, board.D5)]
     rows = [digitalio.DigitalInOut(x) for x in (
         board.D21, board.D20, board.D26, board.D19)]
     keys = ((1, 2, 3), (4, 5, 6), (7, 8, 9), ("*", 0, "#"))
     keypad = adafruit_matrixkeypad.Matrix_Keypad(rows, cols, keys)
     def compare(a, b): return len(a) == len(b) and len(
         a) == sum([1 for i, j in zip(a, b) if i == j])
     password = set()
     p = ''
     while True:
         keys = keypad.pressed_keys
         if keys:
             print("Pressed: ", keys)
             for key in keys:
                 password.add(str(key))
             if len(password) == 4:
                 status = ''
                 if compare(self.password, password):
                     status = 'Found'
                 else:
                     status = 'Not Found'
                     requests.post('http://localhost:5000/bazar')
                 data = {'username': self.name, 'status': status,
                         'password': str("".join(password))}
                 r = requests.post(self.url, data=data)
                 password.clear()
                 p = ''
                 print('Sending {}'.format(r.status_code))
         time.sleep(0.1)
예제 #5
0
 def __init__(self, keys):
     cols = [DigitalInOut(x) for x in (board.GP3, board.GP4, board.GP5)]
     rows = [
         DigitalInOut(x) for x in (board.GP29_A3, board.GP28_A2,
                                   board.GP27_A1, board.GP26_A0)
     ]
     self.keypad = adafruit_matrixkeypad.Matrix_Keypad(rows, cols, keys)
예제 #6
0
파일: keypad.py 프로젝트: Igoranze/LockerPi
def main():
    """
    Main starting application
    """
    # Membrane 3x4 matrix keypad on Raspberry Pi -
    # https://www.adafruit.com/product/419
    cols = [
        digitalio.DigitalInOut(x) for x in (board.D26, board.D20, board.D21)
    ]
    rows = [
        digitalio.DigitalInOut(x)
        for x in (board.D5, board.D6, board.D13, board.D19)
    ]

    # 3x4 matrix keypad on Raspberry Pi -
    # rows and columns are mixed up for https://www.adafruit.com/product/3845
    # cols = [digitalio.DigitalInOut(x) for x in (board.D13, board.D5, board.D26)]
    # rows = [digitalio.DigitalInOut(x) for x in (board.D6, board.D21, board.D20, board.D19)]

    keys = (("#", 0, "*"), (9, 8, 7), (6, 5, 4), (3, 2, 1))

    keypad = adafruit_matrixkeypad.Matrix_Keypad(rows, cols, keys)
    led = LED(17)
    door = LED(4)

    code = ""

    while True:
        keys = keypad.pressed_keys
        key_pressed = get_pressed_key(keys, led)

        if key_pressed is None:
            continue

        if key_pressed == "*":
            code = ""
            door.off()
            led.off()
        else:
            code = code + key_pressed

        if check_code(code, door, led):
            print("Door is now open for 10 seconds")
            time.sleep(10)
            door.off()
            led.off()
            code = ""
            print("Door is closed")

        print("code: {}".format(code))

        time.sleep(0.1)
예제 #7
0
 def __init__(self):
   cols = [digitalio.DigitalInOut(x) for x in (board.D5, board.D6, board.D13)]
   rows = [digitalio.DigitalInOut(x) for x in (board.D19, board.D26, board.D20, board.D21)]
   keys = ((1, 2, 3),
     (4, 5, 6),
     (7, 8, 9),
     ('*', 0, '#'))
   self.keypad = adafruit_matrixkeypad.Matrix_Keypad(rows, cols, keys)
   self.pwd_len = 4
   self.time = time.time()
   self.time_out = 4
   self.debounce = 0.1
   self.input = []
   self.let_go = True
예제 #8
0
def setup_keypad():

    cols = [
        digitalio.DigitalInOut(x) for x in (board.D26, board.D20, board.D21)
    ]
    rows = [
        digitalio.DigitalInOut(x)
        for x in (board.D5, board.D6, board.D13, board.D19)
    ]

    keys = ((1, 2, 3), (4, 5, 6), (7, 8, 9), ('*', 0, '#'))

    keypad = adafruit_matrixkeypad.Matrix_Keypad(rows, cols, keys)

    return keypad
예제 #9
0
파일: keypad.py 프로젝트: PotatoDrug/Alarmy
    def __init__(self, hwalert, lcd):
        self.code = ''
        self.hwalert = hwalert
        self.armed = False
        self.thread = None
        self.lcd = lcd
        # 4x4 matrix keypad
        rows = [
            DigitalInOut(x)
            for x in (board.D4, board.D17, board.D27, board.D22)
        ]
        cols = [
            DigitalInOut(x)
            for x in (board.D18, board.D23, board.D24, board.D25)
        ]
        keys = (('1', '2', '3', 'A'), ('4', '5', '6', 'B'),
                ('7', '8', '9', 'C'), ('*', '0', '#', 'D'))

        self.keypad = adafruit_matrixkeypad.Matrix_Keypad(rows, cols, keys)
예제 #10
0
import digitalio
import board
import adafruit_matrixkeypad

# Membrane 3x4 matrix keypad on Raspberry Pi -
# https://www.adafruit.com/product/419
cols = [digitalio.DigitalInOut(x) for x in (board.D26, board.D20, board.D21)]
rows = [
    digitalio.DigitalInOut(x)
    for x in (board.D5, board.D6, board.D13, board.D19)
]

# 3x4 matrix keypad on Raspberry Pi -
# rows and columns are mixed up for https://www.adafruit.com/product/3845
# cols = [digitalio.DigitalInOut(x) for x in (board.D13, board.D5, board.D26)]
# rows = [digitalio.DigitalInOut(x) for x in (board.D6, board.D21, board.D20, board.D19)]

keys = ((1, 2, 3), (4, 5, 6), (7, 8, 9), ('*', 0, '#'))

keypad = adafruit_matrixkeypad.Matrix_Keypad(rows, cols, keys)

while True:
    keys = keypad.pressed_keys
    if keys:
        print("Pressed: ", keys)

    if keys == [0]:
        print("true")
    else:
        print("false")
    time.sleep(0.1)
예제 #11
0
keys_entered = '0'
keys_entered_1 = ""
operator = ''
hold_operand = False
negative = False
percent = False
calculate = False

cols = [DigitalInOut(x) for x in (board.D0, board.D1, board.D5, board.D6)]        # define hardware pin mapping for MCU and passive
rows = [DigitalInOut(x) for x in (board.D9, board.D10, board.D11, board.D12)]     # keyboard key layout.
keys = ((1, 2, 3, '/'),
        (4, 5, 6, 'x'),
        (7, 8, 9, '+'),
        ('.', 0, '=', 'AC'))

keypad = adafruit_matrixkeypad.Matrix_Keypad(rows, cols, keys)      # create an instance of the Adafruit Matrix_Keypad class to allow      
                                                                    # keyboard scan and key press detection.
while True:
    keys = keypad.pressed_keys
    if len(keys) > 0:
        button = str(keys[0])
        if button is 'AC':                              # clear all entries and flags if 'AC' is pressed.
            keys_entered = '0'
            keys_entered_1 = ''
            negative = False
            operator = ''
            hold_operand = False
            percent = False
        elif button in '1234567890.':
            if calculate:                               # calculate flag is set to True immediately after the = key has been
                keys_entered = ''                       # pressed, so new key_entered is began with appropriate flags reset.
 def __init__(self, keys):
     cols = [DigitalInOut(x) for x in (board.D10, board.D9, board.D8)]
     rows = [DigitalInOut(x) for x in (board.A3, board.D4, board.D5, board.D6)]
     self.keypad = adafruit_matrixkeypad.Matrix_Keypad(rows, cols, keys)
    def __init__(self, rotation=0):
        self._rotation = rotation

        # Define NeoPixels
        self.pixels = _NeoPixelArray(board.NEOPIXEL,
                                     width=8,
                                     height=4,
                                     rotation=rotation)
        """Sequence like object representing the 32 NeoPixels on the Trellis M4 Express, Provides a
        two dimensional representation of the NeoPixel grid.

        This example lights up the first pixel green:

        .. code-block:: python

            import adafruit_trellism4

            trellis = adafruit_trellism4.TrellisM4Express()

            trellis.pixels[0, 0] = (0, 255, 0)

        **Options for** ``pixels``:

        ``pixels.fill``: Colors all the pixels a given color. Provide an (R, G, B) color tuple
        (such as (255, 0, 0) for red), or a hex color value (such as 0xff0000 for red).

            This example colors all pixels red:

            .. code-block:: python

                import adafruit_trellism4

                trellis = adafruit_trellism4.TrellisM4Express()

                trellis.pixels.fill((255, 0, 0))

        ``pixels.width`` and ``pixels.height``: The width and height of the grid. When ``rotation``
        is 0, ``width`` is 8 and ``height`` is 4.

            This example colors all pixels blue:

            .. code-block:: python

                import adafruit_trellism4

                trellis = adafruit_trellism4.TrellisM4Express()

                for x in range(trellis.pixels.width):
                    for y in range(trellis.pixels.height):
                        trellis.pixels[x, y] = (0, 0, 255)

        ``pixels.brightness``: The overall brightness of the pixel. Must be a number between 0 and
        1, where the number represents a percentage between 0 and 100, i.e. ``0.3`` is 30%.

            This example sets the brightness to ``0.3`` and turns all the LEDs red:

            .. code-block:: python

                import adafruit_trellism4

                trellis = adafruit_trellism4.TrellisM4Express()

                trellis.pixels.brightness = 0.3

                trellis.pixels.fill((255, 0, 0))
        """

        cols = []
        for x in range(8):
            col = digitalio.DigitalInOut(getattr(board, "COL{}".format(x)))
            cols.append(col)

        rows = []
        for y in range(4):
            row = digitalio.DigitalInOut(getattr(board, "ROW{}".format(y)))
            rows.append(row)

        key_names = []
        for y in range(8):
            row = []
            for x in range(4):
                if rotation == 0:
                    coord = (y, x)
                elif rotation == 180:
                    coord = (7 - y, 3 - x)
                elif rotation == 90:
                    coord = (3 - x, y)
                elif rotation == 270:
                    coord = (x, 7 - y)
                row.append(coord)
            key_names.append(row)

        self._matrix = adafruit_matrixkeypad.Matrix_Keypad(
            cols, rows, key_names)
예제 #14
0
 def __init__(self, keys):
     cols = [digitalio.DigitalInOut(x) for x in (board.GP11, board.GP10, board.GP9)]
     rows = [digitalio.DigitalInOut(x) for x in (board.GP12, board.GP13, board.GP14, board.GP15)]
     self.keypad = adafruit_matrixkeypad.Matrix_Keypad(rows, cols, keys)
]

# KEYBOARD_KEYS below is a list of 9 items. In programming counting starts at 0.
# So output_values has 9 values that can be used
# to look up KEYBOARD_KEYS.
output_values = (
    (0, 1, 2),
    (3, 4, 5),
    (6, 7, 8),
)

# The following code takes a collection of rows and columns and converts them to
# one of the output_values. output_values is a 3 x 3, just like how the BYO Keyboard
# has 3 rows and 3 columns. When the first button is pressed, a 0 is output
# as seen in the code below.
keypad = adafruit_matrixkeypad.Matrix_Keypad(rows, columns, output_values)

# Above we define output_values as 0 through 8. 0 will point to Keycode.ONE and so one.
# For more Keycodes, check here: https://circuitpython.readthedocs.io/projects/hid/en/latest/index.html
KEYBOARD_KEYS = [
    Keycode.ONE,
    Keycode.TWO,
    Keycode.THREE,
    Keycode.FOUR,
    Keycode.FIVE,
    Keycode.SIX,
    Keycode.SEVEN,
    Keycode.EIGHT,
    Keycode.NINE,
]
예제 #16
0
# handles the logic for what the remote does depending on user interaction
deviceState = 0

# dictionary for keypresses
key_pressed_dict = {}

# Row D6 is now enabled/initialized yet
keypad_rows = [digitalio.DigitalInOut(pin) for pin in (board.A0, board.A1, board.A2, board.A3, board.D6)]
cols = [digitalio.DigitalInOut(pin) for pin in (board.A4, board.A5)]

keys = [
    ["Power", "Volume+", "Volume-", "F1", "F3"],
    ["Source", "Channel+", "Channel-", "F2", "F4"],
]

remote_keypad = adafruit_matrixkeypad.Matrix_Keypad(cols, keypad_rows, keys)
keyPressed = False

# IR setup
pulsein = pulseio.PulseIn(board.D12, maxlen=120, idle_state=True)
decoder = adafruit_irremote.GenericDecode()

# size must match what you are decoding! for NEC use 4
received_code = bytearray(4)

# Docs for adafruit_irremote: (https://circuitpython.readthedocs.io/projects/irremote/en/latest/api.html#implementation-notes)
# Article for IR Apple Remote Code: https://www.hackster.io/BlitzCityDIY/circuit-python-ir-remote-for-apple-tv-e97ea0
# IR Test Code (Apple Remote): https://github.com/BlitzCityDIY/Circuit-Python-Apple-TV-IR-Remote/blob/master/ciruitPython_appleTv_IR-Remote
# pwm out test
OKAY = bytearray(b'\x88\x1e\xc5 ')  # decoded [136, 30, 197, 32]
ir_transmitter = adafruit_irremote.GenericTransmit((9050, 4460), (550, 1650), (570, 575), 575)
#!/usr/bin/env python3
import board as bd
import digitalio as dio
import adafruit_matrixkeypad as mat_keypad
import time

col_pins = [bd.D26, bd.D19, bd.D13, bd.D6]
row_pins = [bd.D21, bd.D20, bd.D16, bd.D12]

rows = []
cols = []

for row_pin in row_pins:
    rows.append(dio.DigitalInOut(row_pin))

for col_pin in col_pins:
    cols.append(dio.DigitalInOut(col_pin))

keys = (("D", "#", 0, "*"), ("C", 9, 8, 7), ("B", 6, 5, 4), ("A", 3, 2, 1))
keypad = mat_keypad.Matrix_Keypad(rows, cols, keys)

while True:
    kp = keypad.pressed_keys
    if kp:
        print(f"Pressed : {kp}")
    time.sleep(0.2)
import time
import digitalio
import RPi.GPIO as GPIO #import RPi.GPIO as GPIO
import adafruit_matrixkeypad as amk #import Adafruit Matrix Keypad Library as amk

1, 2, 3,  4,  5,  6,  7,  8
5, 6, 13, 19, 26, 16, 20, 21

cols = [GPIO.setup(x,GPIO.IN) for x in (13, 5, 26, 21)]
rows = [GPIO.setup(x,GPIO.IN) for x in (6, 20, 16, 19)]
keys = ((1, 2, 3, 'A'),
        (4, 5, 6, 'B'),
        (7, 8, 9, 'C'),
        ('*', 0, '#', 'D'))

keypad = amk.Matrix_Keypad(rows, cols, keys)

while True:
        keys = keypad.pressed_keys
        if keys:
                print("Press: ", keys)
                time.sleep(0.1)
"""
import time
import digitalio
import board
import adafruit_matrixkeypad

cols = [digitalio.DigitalInOut(x) for x in (board.D11, board.D13, board.D9)]
rows = [digitalio.DigitalInOut(x) for x in (board.D12, board.D5, board.D6, board.D10)]
keys = ((1, 2, 3, 'A'),