diff keys.py @ 1:5a93179ccae9

7key code
author drewp@bigasterisk.com
date Thu, 11 May 2023 15:07:10 -0700
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/keys.py	Thu May 11 15:07:10 2023 -0700
@@ -0,0 +1,26 @@
+from machine import Pin
+class Keys:
+    def __init__(self):
+                
+        self.rows = [
+            Pin(23, Pin.OUT),
+            Pin(22, Pin.OUT),
+        ]
+        self.cols = [
+            Pin(36, Pin.IN, pull=-1),  # these don't have internal pullups
+            Pin(39, Pin.IN, pull=-1),
+            Pin(34, Pin.IN, pull=-1),
+            Pin(35, Pin.IN, pull=-1)
+        ]
+        self.prev = ''
+
+    def newKeysDown(self):
+        res = ''
+        for r, rp in enumerate(self.rows):
+            rp.value(0)
+            for c, cp in enumerate(self.cols):
+                res += str(1 - cp())
+            rp.value(1)
+        if res != self.prev:
+            self.prev = res
+            return res
\ No newline at end of file