6 years, 6 months ago.

How to use DigitalIn and DigitalOut to scan a 4x3 keypad and return the key pressed

I am looking for a simplified version of these keypad examples on mbed. I am really new to C so I am not looking to make anything fancy, I just want to understand how to print the key pressed on serial connection. I have gotten button 1 to work, but sometimes it doesnt work, and when it does it prints a lot of "1" on the terminal.

The requirements for this project is to use DigitalIn and DigitalOut. and give 10ms low signal on one of the outputs, and then read the 3 columns to determine what button is pressed. Here is the code I have so far and I have no clue what to do to make this work and the keypad examples on here is not much help, since I dont understand it all.

this is for a STM32L476VG Dev board.

  1. include "mbed.h"

DigitalOut r0(PD_0); DigitalOut r1(PB_7); DigitalOut r2(PB_6); DigitalOut r3(PA_3); DigitalIn c0(PA_2); DigitalIn c1(PA_1); DigitalIn c2(PA_5);

int main() { c0.mode(PullUp); c1.mode(PullUp); c2.mode(PullUp); DigitalOut rows[4]={r0,r1,r2,r3}; DigitalIn cols[3]={c0,c1,c2}; int i; int x; while(1) { for(i=0;i<3;i++) rows[i]=1; wait(.1); if(!c1&&(i==1)) { wait(.05); printf("1"); } wait(.1); } }

Be the first to answer this question.