Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 5318

Other projects • Re: Custom Key pad

$
0
0
Ok, having a simulator is almost as good as the real thing, and has helped me show that this code (slightly different to previous code) should work.

Code:

# Code for shift-register based keypad## Raspberry Pi Pico connected to keypad PCB# via JP1 (14-pin IDC header). Keypad is# constructed from nine '165 shift registers# in series, therefore 72 bits to shift out.# Connect Pico 3.3V OUT pin 36 to JP1 pin 14 (VCC)# Connect Pico GND pin 38 to JP1 pin 1 (GND)# Connect Pico GP0 pin 1 to JP1 pin 2 (DATA)# Connect Pico GP2 pin 4 to JP1 pin 6 (CLK)# Connect Pico GP3 pin 5 to JP1 pin 8 (~PL)# Import libraries we needfrom machine import Pin# GPIOs connected to keypad PCB dataPIN = 0 latchPIN = 3 # Active lowclockPIN = 2 # Shift data on rising edge# Set up pin objects# Pull-up not needed on data pin because it is driven externallydata=Pin(dataPIN, Pin.IN)# Include initial pin states herelatch=Pin(latchPIN, Pin.OUT, value=1)clock=Pin(clockPIN, Pin.OUT, value=0)# Setup done. Repeat the following code regularly to read# the keypad state, ideally in a function.# Pulse the latch pin to load pins into registers.latch.value(0) # Latch pins into registerlatch.value(1)# Now, shift out registers from the PCB and show the value# For testing look at only the first 8 bitsfor i in range(8):  print("D%s %s"%(7-i,data.value()))  # Bits are shifted out MSb (bit 7) first  clock.value(1)  # Clock out next bit  clock.value(0)

Statistics: Posted by ame — Fri May 10, 2024 3:52 am



Viewing all articles
Browse latest Browse all 5318

Trending Articles