Just a little testing code for the debugger:
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#define expander B0111001 // Address with three address pins grounded.
// Note that the R/W bit is not part of this address.
// B0111000 = ap
// B0100000 = p
int pinwaarde;
int pinnummer;
uint8_t bell[8] = {0x4,0xe,0xe,0xe,0x1f,0x0,0x4};
uint8_t note[8] = {0x2,0x3,0x2,0xe,0x1e,0xc,0x0};
uint8_t clock[8] = {0x0,0xe,0x15,0x17,0x11,0xe,0x0};
uint8_t heart[8] = {0x0,0xa,0x1f,0x1f,0xe,0x4,0x0};
uint8_t duck[8] = {0x0,0xc,0x1d,0xf,0xf,0x6,0x0};
uint8_t check[8] = {0x0,0x1,0x3,0x16,0x1c,0x8,0x0};
uint8_t cross[8] = {0x0,0x1b,0xe,0x4,0xe,0x1b,0x0};
uint8_t retarrow[8] = { 0x1,0x1,0x5,0x9,0x1f,0x8,0x4};
LiquidCrystal_I2C lcd(0x38,16,4); // set the LCD address to 0x20 for a 16 chars and 2 line display
void setup()
{
lcd.init(); // initialize the lcd
lcd.backlight();
lcd.createChar(0, bell);
lcd.createChar(1, note);
lcd.createChar(2, clock);
lcd.createChar(3, heart);
lcd.createChar(4, duck);
lcd.createChar(5, check);
lcd.createChar(6, cross);
lcd.createChar(7, retarrow);
lcd.home();
lcd.print("Hello world...");
lcd.setCursor(0, 1);
lcd.print(" i ");
lcd.print(3, BYTE);
lcd.print(" arduinos!");
expanderWrite(B00000000);
// displayKeyCodes();
}
void loop() {
pinwaarde = (expanderRead());
lcd.setCursor(16, 1);
////////////////////////////////// NONE ///////////////////////////////
if (pinwaarde <= 0) {
pinnummer = 0;
lcd.print("Button: NONE ");
}
////////////////////////////////// PIN 8 ///////////////////////////////
if (pinwaarde >= 128) {
pinnummer = 8;
pinwaarde = (pinwaarde - 128); }
// else{ pinnummer = 80; }
////////////////////////////////// PIN 7 ///////////////////////////////
if (pinwaarde >= 64) {
pinnummer = 7;
pinwaarde = (pinwaarde - 64); }
////////////////////////////////// PIN 6 ///////////////////////////////
if (pinwaarde >= 32) {
pinnummer = 6;
lcd.print("Button: HOME");
pinwaarde = (pinwaarde - 32); }
////////////////////////////////// PIN 5 ///////////////////////////////
if (pinwaarde >= 16) {
pinnummer = 5;
lcd.print("Button: ENTER");
pinwaarde = (pinwaarde - 16); }
////////////////////////////////// PIN 4 ///////////////////////////////
if (pinwaarde >=
{
pinnummer = 4;
lcd.print("Button: LEFT");
pinwaarde = (pinwaarde -
; }
////////////////////////////////// PIN 3 ///////////////////////////////
if (pinwaarde >= 4) {
pinnummer = 3;
lcd.print("Button: RIGHT");
pinwaarde = (pinwaarde - 4); }
////////////////////////////////// PIN 2 ///////////////////////////////
if (pinwaarde >= 2) {
pinnummer = 2;
lcd.print("Button: DOWN");
pinwaarde = (pinwaarde - 2); }
////////////////////////////////// PIN 1 ///////////////////////////////
if (pinwaarde >= 1) {
pinnummer = 1;
lcd.print("Button: UP ");
pinwaarde = (pinwaarde - 1); }
////////////////////////////////// DEBUG ///////////////////////////////
delay(100);
}
void expanderWrite(byte _data ) {
Wire.beginTransmission(expander);
Wire.send(_data);
Wire.endTransmission();
}
byte expanderRead() {
byte _data;
Wire.requestFrom(expander, 1);
if(Wire.available()) {
_data = Wire.receive();
}
return _data;
}