Comment utiliser un clavier 4×4 avec Arduino
Tout beau tout frais, il est arrivé mon KeyPad 4×4. La commande est presque terminée. J’ai encore un ou deux items a recevoir mais je pense qu’on va lancer la prochaine commande 🙂
J’ai vraiment rusher l’article. En fait je l’ai fais uniquement pour me rappeler de mon code car le PinOut du clavier est un peu chiant perturbant.
Etape 1 - Télécharger et installer la librairie
Télécharger et installer la librairie keypad de Alexander Brevig
Télécharger la librairie keypad
Etape 2 - Envoyer le code vers l’Arduino
Chargez le code d’exemple nommé HelloKeypad en allant dans: fichier -> exemples -> Keypad->HelloKeypad. Et uploadez-le sur votre Arduino.
Branchements
Code d’exemple HelloKeypad - Code Arduino clavier 4×4
Le code est légèrement modifié pour mon pinout et mon clavier 4×4.
/* @file HelloKeypad.pde
|| @version 1.0
|| @author Alexander Brevig
|| @contact [email protected]
||
|| @description
|| | Demonstrates the simplest use of the matrix Keypad library.
|| #
*/
#include <Keypad.h>
const byte ROWS = 4; //four rows
const byte COLS = 4; //three columns
char keys[ROWS][COLS] = {
{'1','2','3','4'},
{'5','6','7','8'},
{'9','a','b','c'},
{'d','e','f','g'}
};
byte rowPins[ROWS] = {9, 8, 7, 6}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {5, 4, 3, 2}; //connect to the column pinouts of the keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup(){
Serial.begin(9600);
}
void loop(){
char key = keypad.getKey();
if (key){
Serial.println(key);
}
}




0 commentaires