J'ai fais un code a l'aide du programme MultiKey de la librairie et de mon précédent programme pour faire fonctionner un écran i2c
Voila ce que ça donne :
// include the library code:
#include <Wire.h>
#include <Adafruit_MCP23017.h>
#include <Adafruit_RGBLCDShield.h>
Adafruit_RGBLCDShield lcd = Adafruit_RGBLCDShield();
// Change Backlight color
#define WHITE 0x7
//Keypad
#include <Keypad.h>
const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns
char keys[ROWS][COLS] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};
byte rowPins[ROWS] = {5, 4, 3, 2}; //connect to the row pinouts of the kpd
byte colPins[COLS] = {8, 7, 6}; //connect to the column pinouts of the kpd
Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
unsigned long loopCount;
unsigned long startTime;
String msg;
//Keypad end
void setup() {
// Debugging output
Serial.begin(9600);
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
//Keypad
loopCount = 0;
startTime = millis();
msg = "";
//Keypad end
// Print a message to the LCD. We track how long it takes since
// this library has been optimized a bit and we're proud of it :)
lcd.print(" Tirelire");
lcd.setCursor(0, 1);
lcd.print (" automatise");
}
uint8_t i=0;
void loop() {
loopCount++;
if ( (millis()-startTime)>5000 ) {
Serial.print("Average loops per second = ");
Serial.println(loopCount/5);
startTime = millis();
loopCount = 0;
}
// Fills kpd.key[ ] array with up-to 10 active keys.
// Returns true if there are ANY active keys.
if (kpd.getKeys())
{
for (int i=0; i<LIST_MAX; i++) // Scan the whole key list.
{
if ( kpd.key[i].stateChanged ) // Only find keys that have changed state.
{
switch (kpd.key[i].kstate) { // Report active key state : IDLE, PRESSED, HOLD, or RELEASED
case PRESSED:
msg = " PRESSED.";
break;
case HOLD:
msg = " HOLD.";
break;
case RELEASED:
msg = " RELEASED.";
break;
case IDLE:
msg = " IDLE.";
}
Serial.print("Key ");
Serial.print(kpd.key[i].kchar);
Serial.println(msg);
}
}
}
} // End loop
A part le message d'introduction, rien ne s'affiche sur l'écran quand j'appuie sur des touches. Par contre lorsque j'appuie sur des touches, la led TX de l'arduino mega clignote, ce qui veut dire, je pense, que mon arduino détecte bien le clavier.
Comment je pourrais faire en modifiant mon programme pour afficher simplement le chiffre sur lequel j'appuie ? Par exemple, lorsque j'appuie sur "1", "1" s'affiche sur l'écran.
Si j'arrive a faire ça, je pense que le reste ira tout seul.
Merci