interface with 3x4 keypad

69-cat

Member
Been away for a while...I am working on a project for my work to display safety videos on a TV by pressing buttons using a 3x4 keypad to communicate to a Picaxe. I know I can pull this off by using many push buttons and input pins but was hoping to interface via this keypad. The MP4 player is setup to loop a file (000.mp4) until an selection is made. I am using an MP4 player (Sprite) that I have used for my Halloween props which is interfaced with a Picaxe, inputs are triggered using PIRs to trigger a selection via serial data. My question is, can a Picaxe interface with a 3x4 keypad to make a selection within the player? i.e. by pressing "2 buttons" 01, the file 001 would play, by pressing 21, video file 021 would play and so on. The max the player can have up to 200 files but I am only looking at and 30 total. I have attached the very simple code that I use for my props to show how the serial interface works with the Sprite player. The LED in my code is just for reference indicator.


Code:
'this circuit is on perf board
#picaxe 14m2
setfreq m8
symbol baud = T9600_8
symbol pb1 = pinc.3
symbol pb2 = pinc.4
symbol mp4_tx = b.1
symbol mp4_rx = b.2
symbol LED_1 = C.0


main:
if pb1 = 1 then goto vid1
if pb2 = 1 then goto vid2
goto main
vid1:
serout mp4_tx, baud, ($01)
serin mp4_rx, baud, ($EE) ; Wait until ended from the sprite
high LED_1                'LED comes on after the video has stopped
pause 5000
low LED_1
goto main

vid2:
serout mp4_tx, baud, ($02)
serin mp4_rx, baud, ($EE) ; Wait until ended from the sprite
high LED_1                'LED comes on after the video has stopped
pause 10000
low LED_1
goto main
 

AllyCat

Senior Member
Hi,

Yes the easiest concept is to use an ADC input (but multiplexing the Row/Column pins onto 7 PICaxe pins may be ultimately more reliable): There are other threads/code snippets on the forum but typically, connect resistors of 0 , 1k , 2k and 3k ohms to the keypad "row" pins and 0 , 4k and 8k to the "column" pins. Then, measuring between the commoned row and column resistors should give resistance values of 0 , 1 , ... , 11k depending which key is pressed.

Put the above "variable resistor" in a potential divider across the Supply - Ground pins and connect the junction to an ADC input. The other divider resistor might be anything from say 10k upwards, depending whether you want to determine the ADC values that correspond to each button-press by "trial and error" or by calculation. The "no button pressed" value should be (close to) 0 or 255 and you can "map" the buttons to the ADC values using (twelve) SELECT .. CASE or IF .. THEN ..ELSE .... or (one) calculated ON .. GOTO commands.

To create a two (or more) digit number from the keypad, read a first (ADC) value and call it "tens" (and wait for the button to be released) then a second and call it "units". The final number is then "tens * 10 + units", etc... But the program may need to take into account "contact bounce", incorrect values (perhaps a "cancel" button) and failure to press a second button in sufficient time, etc.. As Pete says, long PAUSEs should be avoided, for example by using a polling strategy.

Cheers, Alan.
 
Top