Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Keypad.h>
- const byte ROWS = 4; //four rows
- const byte COLS = 4; //four columns
- //define the cymbols on the buttons of the keypads
- char hexaKeys[ROWS][COLS] =
- { {'1', '2', '3', 'A'},
- {'4', '5', '6', 'B'},
- {'7', '8', '9', 'C'},
- {'*', '0', '#', 'D'}
- };
- byte rowPins[ROWS] = {3, 2, 1, 0}; //connect to the row pinouts of the keypad
- byte colPins[COLS] = {7, 6, 5, 4}; //connect to the column pinouts of the keypad
- //initialize an instance of class NewKeypad
- Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
- String minhaStr ;
- unsigned long meuValor;
- char kpadState;
- char customKey ;
- char oldKey ;
- //-----------------------------------------
- void setup()
- {
- Serial.begin(9600);
- }
- //-----------------------------------------
- void loop()
- {
- customKey = customKeypad.getKey();
- kpadState = customKeypad.getState();
- switch ( kpadState )
- {
- case PRESSED:
- if (customKey)
- {
- oldKey = customKey;
- if ((customKey >= '0' ) and (customKey <= '9'))
- {
- minhaStr += customKey;
- meuValor = minhaStr.toInt();
- Serial.print("meuValor "); Serial.println(meuValor);
- }
- }
- break;
- case HOLD:
- switch (oldKey)
- {
- case '2':
- Serial.print("opcao "); Serial.println("A");
- break;
- case '4':
- Serial.print("opcao "); Serial.println("B");
- break;
- case '6':
- Serial.print("opcao "); Serial.println("C");
- break;
- case '8':
- Serial.print("opcao "); Serial.println("D");
- break;
- }
- break;
- case RELEASED:
- oldKey = ' ';
- break;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement