I just bought the "Shield-LCD-16x2" to my Arduino. I found something strange. When edit something on row 2 and position 16, the buttons do not work anymore. I tried it on two different Arduinos. See the modified code below (based on the example code Olimex provide).
"lcd.readButtons" and "buttons & 0x02" will stay "0" all time.
Any solution?
////////////////////////////
#include <LCD16x2.h>
#include <Wire.h>
LCD16x2 lcd;
int buttons;
void setup(){
Wire.begin();
Serial.begin(9600);
lcd.lcdSetBlacklight(100);
lcd.lcdClear();
lcd.lcdGoToXY(2,1);
lcd.lcdWrite("BUT1:");
lcd.lcdGoToXY(10,1);
lcd.lcdWrite("BUT2:");
lcd.lcdGoToXY(2,2);
lcd.lcdWrite("BUT3:");
lcd.lcdGoToXY(10,2);
lcd.lcdWrite("BUT4:");
}
void loop(){
/*
If I add the two lines, type anything (X) on row 2
and position 16 - every read button will be 0.
No button work anymore when push.
*/
//!
lcd.lcdGoToXY(16,2);
lcd.lcdWrite("X");
//!
buttons = lcd.readButtons();
Serial.print(lcd.readButtons());
Serial.print("--> ");
Serial.print(buttons & 0x01);
Serial.print(", ");
Serial.print(buttons & 0x02);
Serial.print(", ");
Serial.print(buttons & 0x04);
Serial.print(", ");
Serial.print(buttons & 0x08);
Serial.println();
lcd.lcdGoToXY(7,1);
if(buttons & 0x01)
lcd.lcdWrite("0");
else
lcd.lcdWrite("1");
lcd.lcdGoToXY(15,1);
if(buttons & 0x02)
lcd.lcdWrite("0");
else
lcd.lcdWrite("1");
lcd.lcdGoToXY(7,2);
if(buttons & 0x04)
lcd.lcdWrite("0");
else
lcd.lcdWrite("1");
lcd.lcdGoToXY(15,2);
if(buttons & 0x08)
lcd.lcdWrite("0");
else
lcd.lcdWrite("1");
}
My colleague tested your code without any changes with OLIMEX OLIMEXINO-328 and SHIELD-LCD16x2 and the buttons worked fine.
What Arduno board exactly are you using?
Edit: no issues with OLIMEXINO-32U4 either
Hi,
Something strange happend when I installed board and library.
After reinstallation, it works! :)
Thanks for your time!