Bonjour a tous
Comme décris dans le titre je cherche a faire une boite a bouton afin de contrôler
certain paramètre d’un jeu de simulation auto.
Grace à plusieurs recherche je suis arrivé a ça (Voir code)
Mon problème et que je voudrais inclure l’allumage d’une led (Ledpin1 sur borne 13)
si j’appuie sur un bouton , disons le 25, par exemple, mais je ne sais pas ni
comment ni ou inclure cette séquence
Merci de m’éclairer de vos lumière avertis
Cordialement
Fifou63
#include <Keypad.h>
#include <Joystick.h>
#define ENABLE_PULLUPS
#define NUMROTARIES 3
#define NUMBUTTONS 25
#define NUMROWS 5
#define NUMCOLS 5
#define Ledpin1 13
//define the symbols on the buttons of the keypads
byte buttons[NUMROWS][NUMCOLS] = {
{1,2,3,4,5},
{6,7,8,9,10},
{11,12,13,14,15},
{16,17,18,19,20},
{21,22,23,24,25},
};
struct rotariesdef {
byte pin0;
byte pin1;
int ccwchar;
int cwchar;
volatile unsigned char state;
};
rotariesdef rotaries[NUMROTARIES] {
{0,1,26,27,0},
{2,3,28,29,0},
{4,5,30,31,0},
};
#define DIR_CCW 0x10
#define DIR_CW 0x20
#define R_START 0x0
#define R_CW_FINAL 0x1
#define R_CW_BEGIN 0x2
#define R_CW_NEXT 0x3
#define R_CCW_BEGIN 0x4
#define R_CCW_FINAL 0x5
#define R_CCW_NEXT 0x6
const unsigned char ttable[A0][A4] = {
// R_START
{R_START, R_CW_BEGIN, R_CCW_BEGIN, R_START},
// R_CW_FINAL
{R_CW_NEXT, R_START, R_CW_FINAL, R_START | DIR_CW},
// R_CW_BEGIN
{R_CW_NEXT, R_CW_BEGIN, R_START, R_START},
// R_CW_NEXT
{R_CW_NEXT, R_CW_BEGIN, R_CW_FINAL, R_START},
// R_CCW_BEGIN
{R_CCW_NEXT, R_START, R_CCW_BEGIN, R_START},
// R_CCW_FINAL
{R_CCW_NEXT, R_CCW_FINAL, R_START, R_START | DIR_CCW},
// R_CCW_NEXT
{R_CCW_NEXT, R_CCW_FINAL, R_CCW_BEGIN, R_START},
};
byte rowPins[NUMROWS] = {A5, 9, 10, 11, 12}; //connect to the row pinouts of the keypad
byte colPins[NUMCOLS] = {2, 3, 4, 7, 8}; //connect to the column pinouts of the keypad
//initialize an instance of class NewKeypad
Keypad buttbx = Keypad( makeKeymap(buttons), rowPins, colPins, NUMROWS, NUMCOLS);
void setup() {
Joystick.begin();
rotary_init();
}
void loop() {
CheckAllEncoders();
CheckAllButtons();
}
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;
}
}
}
}
}