From d2e87b3e709dc0039537e6bf6dc03ec703567ef2 Mon Sep 17 00:00:00 2001 From: xs5871 Date: Sun, 10 Apr 2022 22:36:11 +0000 Subject: [PATCH] add keypad scanner for shift registers --- docs/scanners.md | 25 +++++++++++++++++++++++++ kmk/scanners/keypad.py | 26 ++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/docs/scanners.md b/docs/scanners.md index 70683d7..5660eae 100644 --- a/docs/scanners.md +++ b/docs/scanners.md @@ -74,6 +74,31 @@ class MyKeyboard(KMKKeyboard): ``` +### keypad ShiftRegisterKeys + +This scanner can read keys attached to a parallel-in serial-out shift register +like the 74HC165 or CD4021. Note that you may chain shift registers to load in +as many values as you need. +```python +from kmk.scanners.keypad import ShiftRegisterKeys + +class MyKeyboard(KMKKeyboard): + def __init__(self): + # create and register the scanner + self.matrix = ShiftRegisterKeys( + # require arguments: + clock=board.GP0, + data=board.GP1, + latch=board.GP2, + key_count=8, + # optional arguments with defaults: + value_to_latch=True, # 74HC165: True, CD4021: False + value_when_pressed=False, + interval=0.02, + max_events=64 + ) +``` + ## Digitalio Scanners ### digitalio MatrixScanner diff --git a/kmk/scanners/keypad.py b/kmk/scanners/keypad.py index 381b7b9..5b32ef0 100644 --- a/kmk/scanners/keypad.py +++ b/kmk/scanners/keypad.py @@ -88,3 +88,29 @@ class KeysScanner(KeypadScanner): max_events=max_events, ) super().__init__() + + +class ShiftRegisterKeys(KeypadScanner): + def __init__( + self, + *, + clock, + data, + latch, + value_to_latch=True, + key_count, + value_when_pressed=False, + interval=0.02, + max_events=64, + ): + self.keypad = keypad.ShiftRegisterKeys( + clock=clock, + data=data, + latch=latch, + value_to_latch=value_to_latch, + key_count=key_count, + value_when_pressed=value_when_pressed, + interval=interval, + max_events=max_events, + ) + super().__init__()