Buongiorno a tutti,
sono agli inizi con la programmazione e mi sono dato come obbiettivo la costruzione di una Button box utilizzando la matrice righe/colonne.
Ho cercato uno sketch ed ho apportato solo le modifiche che mi interessavano cercando nel contempo di capirne il funzionamento. La scheda utilizzata è una Leonardo e la matrice nella versione definitiva sarà di 16 pulsanti.
Ho effettuato alcune prove con una matrice 2 x 2 e funziona come mi aspettavo ma avrei necessità di far si che quando il pulsante è attivo sia anche attivo il relativo LED e qui non saprei che pesci pigliare, ho anche letto tutto quanto è contenuto nella libreria KEYPAD ma non sono riuscito a venirne a capo, qui sotto trovate lo sketch come è oggi configurato, se qualcuno mi potesse dare una dritta o farmi anche solo capire quale genere di dato devo pescare per poi fare tutta la programmazione dei LED mi farebbe un regalone!!!
//Arduino IDE 1.6.6 (or above) !
//
//
//1,3,5,7 Are the Row Pins for the Keypad 0,2,4,6 are the Column Pins
//ROW1-COL1÷4 ENG 7-6 HYD 7-4 DOOR 7-2 STS 7-0
//ROW2-COL1÷4 BLEED 5-6 FUEL 5-4 WHEEL 5-2 TO CONF 5-0
//ROW3-COL1÷4 PRESS 3-6 APU 3-4 F/CTL 3-2 EMERCANC 3-0
//ROW4-COL1÷4 ELEC 1-6 COND 1-4 CLR 1-2 RCL 1-0
#include <Keypad.h>
#include <Joystick.h>
#define NUMBUTTONS 16
#define NUMROWS 4
#define NUMCOLS 4
//define the symbols on the buttons of the keypads
byte buttons[NUMROWS][NUMCOLS] = {
{0,1,2,3},
{4,5,6,7},
{8,9,10,11},
{12,13,14,15},
};
byte rowPins[NUMROWS] = {1,3,5,7}; //connect to the row pinouts of the keypad
byte colPins[NUMCOLS] = {0,2,4,6}; //connect to the column pinouts of the keypad
//initialize an instance of class NewKeypad
Keypad buttbx = Keypad( makeKeymap(buttons), rowPins, colPins, NUMROWS, NUMCOLS);
//initialize an Joystick with 56 buttons;
Joystick_ Joystick(JOYSTICK_DEFAULT_REPORT_ID,
JOYSTICK_TYPE_JOYSTICK, 16, 0,
false, false, false, false, false, false,
false, false, false, false, false);
void setup() {
Joystick.begin();
}
void loop() {
CheckAllButtons();
delay(200);
}
void CheckAllButtons(void) {
if (buttbx.getKeys())
{
for (int i=0; i<LIST_MAX; i++) // Scan the whole key list.
{
if ( buttbx.key[i].stateChanged ) // Only find keys that have changed state.
{
switch (buttbx.key[i].kstate) { // Report active key state : IDLE, PRESSED, HOLD, or RELEASED
case PRESSED:
case HOLD:
Joystick.setButton(buttbx.key[i].kchar, 1);
break;
case RELEASED:
case IDLE:
Joystick.setButton(buttbx.key[i].kchar, 0);
break;
}
}
}
}
}
Grazie in anticipo
Max