teste teclado

Dependencies:   mbed Keypad

teste_biblio_keypad.cpp

Committer:
enricoan
Date:
2020-05-27
Revision:
0:5b3b34d4e428

File content as of revision 0:5b3b34d4e428:

#include "mbed.h"
#include "Keypad.h"

Keypad teclado(PC_0, PC_1, PB_0, PA_4, PC_3, PC_2, PC_15, PC_14);
DigitalOut mled(LED1);

int main() {
    char tecla;
    int solta = 1;

    while(1){
        mled = 1; // LED is ON
        wait(0.2); // 200 ms
        mled = 0; // LED is OFF
        wait(1.0); // 1 sec
        
        tecla = teclado.ReadKey();                   //read the current key pressed

        if(tecla == '\0')
            solta = 1;                       //set the flag when all keys are released
           
        if((tecla != '\0') && (solta == 1)) {  //if a key is pressed AND previous key was released
            printf("%c\n", tecla);            
            solta = 0;                       //clear the flag to indicate that key is still pressed
        }
    }
}