view 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 source

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