Stap 1: Het toetsenblok
Het toetsenblok
Hardware:
Ik had 3 soorten cijfertoetsen die ik gespeeld met (schakelaars op een PC board, membraan schakelaar, soft-touch)
Zie de foto's van toetsenborden.
Software:
Ik ben begonnen met de bibliotheek toetsenbord voor eenvoudige matrix stijl toetsenbord mapping. Zie http://playground.arduino.cc/code/Keypad voor meer informatie.
Ik had om te spelen rond met de rij- en kolom toewijzing om mijn matrix schakelaar toetsenblok om te werken. De pin-out in de documentatie was niet correct op een van de toetsenborden. Dus zodra ik de juiste pin-out vastbesloten, de code gehanteerd in de perfectie.
Hier is een stukje code laat zien hoe om de bibliotheek van het toetsenbord te gebruiken:
(Dit is voor de 16 wissels en kruisingen op PC bord)
#include <Keypad.h> const byte ROWS = 4; // define four rows const byte COLS = 4; // define four columns char keys [ROWS] [COLS] = { {'1', '2', '3',' {'4', '5', '6','B'}, {'7', '8', '9','C'}, {'*', '0', '#','-'} }; // Pin R/C // 8 C4 // 7 C3 // 6 C2 // 5 C1 // 4 R1 // 3 R2 // 2 R3 // 1 R4 // Connect 4 * 4 buttons faithfully port, the corresponding digital IO ports panel byte colPins [COLS] = {10,11,12,13}; // Call the function library function Keypad Keypad keypad = Keypad (makeKeymap (keys), rowPins, colPins, ROWS, COLS); void loop () { char key = keypad.getKey (); if (key != NO_KEY) { // Clear if(key == 'C') { state = CLEAR; } }