hi,
I'm trying to make this project from Experimental Avionics.
http://https://www.youtube.com/watch?v=emqc_vi7-Rg
The original project uses a GLCD with a 192x64 resolution while I am using a 128x128 GLCD screen. I managed to changed some X,Y coordinates to suite a 128x128 LCD.
The problem is I am having difficulty in changing the X,Y coordinates in the MENU setting using an encoder. (see attached photo)
it consists of 3 settings EXIT, CLOCK, MIN. AIRSPEED
here is the code from the site
void Menu() {
int SettingItem = 0;
int ButtonPush = 0;
int KeepLoop = true;
int KeepLoop1 = true;
int KeepLoop2 = true;
int encCurrentValue = 0;
int highlightwidth = 192;
int highlighthight = 10;
int textShiftX = 4;
int textShiftY = 10;
int MaxSettings = 3; // number of setting items
byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
int secvalue = 0;
int TimeSetPosition = 0;
String StringSetting1 = "";
String StringSetting2 = "";
int tmpValue = 0;
int tmpMinValue = 0;
int tmpMaxValue = 0;
int i = 0;
GLCD.ClearScreen();
//****************************** Draw the screen ********************************
i = 0;
textAreaSetting0.DefineArea(textShiftX, 1 + textShiftY * i , 29, 1 , System5x7);
textAreaSetting0.ClearArea();
textAreaSetting0.print("Exit");
GLCD.InvertRect(0, highlighthight * i, highlightwidth, highlighthight);
i = 1;
textAreaSetting1.DefineArea(textShiftX, 1 + textShiftY * i , 29, 1 , System5x7);
textAreaSetting1.ClearArea();
//textAreaSetting1.SetFontColor(PIXEL_OFF);
StringSetting1 = "Clock: ";
textAreaSetting1.print(StringSetting1);
i = 2;
textAreaSetting2.DefineArea(textShiftX, 1 + textShiftY * i , 29, 1 , System5x7);
textAreaSetting2.ClearArea();
StringSetting2 = "Airswitch Min Speed: " + String(MinFlightSpeed,DEC) + " Kts";
textAreaSetting2.print(StringSetting2);
//****************************** End of Draw the screen ********************************
while (KeepLoop) {
while (buttonState == LOW) { // button could have been held down at this point. wait fot release
buttonState = digitalRead(Click_Button);
delay(50);
}
// sowing time constantly
readDS3231time(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);
if (secvalue != second) {
StringSetting1 = "Clock: 20";
StringSetting1 += year;
StringSetting1 += "-";
if (month < 10) {
StringSetting1 += "0";
}
StringSetting1 += month;
StringSetting1 += "-";
if (dayOfMonth < 10) {
StringSetting1 += "0";
}
StringSetting1 += dayOfMonth;
StringSetting1 += " ";
if (hour < 10) {
StringSetting1 += "0";
}
StringSetting1 += hour;
StringSetting1 += ":";
if (minute < 10) {
StringSetting1 += "0";
}
StringSetting1 += minute;
StringSetting1 += ":";
if (second < 10) {
StringSetting1 += "0";
}
StringSetting1 += second;
if (SettingItem == 1) {
textAreaSetting1.SetFontColor(PIXEL_OFF);
} else {
textAreaSetting1.SetFontColor(PIXEL_ON);
}
textAreaSetting1.ClearArea();
textAreaSetting1.print(StringSetting1);
secvalue = second;
}
buttonState = digitalRead(Click_Button);
if (buttonState == LOW and bTimer == 0 and MenuItem == 2) {
bTimer = millis();
}
if (buttonState == HIGH and bTimer > 0 and MenuItem == 2) {
ButtonPush = 1;
bTimer = 0;
}
encCurrentValue = myEnc.read()/4;
if (encCurrentValue != encLastValue) {
GLCD.InvertRect(0, highlighthight * SettingItem, highlightwidth, highlighthight);
SettingItem = (SettingItem - (encCurrentValue - encLastValue)) % MaxSettings;
// due to weird implementation of MODULO function I had to do the follwoing line
if (SettingItem <0) {
SettingItem = MaxSettings + SettingItem;
}
GLCD.InvertRect(0, highlighthight * SettingItem, highlightwidth, highlighthight);
encLastValue = encCurrentValue;
ButtonPush = 0;
}
//******************************** Setting UTC time *************************
if (SettingItem == 1 and ButtonPush == 1) {
textAreaSetting1.ClearArea();
textAreaSetting1.SetFontColor(PIXEL_ON);
textAreaSetting1.print(StringSetting1);
GLCD.InvertRect(58+(TimeSetPosition*18), highlighthight+1, 12, highlighthight-2);
while (KeepLoop1) {
encCurrentValue = myEnc.read()/4;
if (encCurrentValue != encLastValue) {
GLCD.InvertRect(58+(TimeSetPosition*18), highlighthight+1, 12, highlighthight-2);
TimeSetPosition = (TimeSetPosition - (encCurrentValue - encLastValue)) % 5;
// due to weird implementation of MODULO function I had to do the follwoing line
if (TimeSetPosition <0) {
TimeSetPosition = 5 + TimeSetPosition;
}
encLastValue = encCurrentValue;
GLCD.InvertRect(58+(TimeSetPosition*18), highlighthight+1, 12, highlighthight-2);
}
buttonState = digitalRead(Click_Button);
if (buttonState == LOW) { // buttom pressed - need to hold the button to exit
bTimer = millis();
while (buttonState == LOW and millis() - bTimer < 1500) { // button released
buttonState = digitalRead(Click_Button);
delay(50);
}
if (millis() - bTimer > 1500) {
KeepLoop1 = false;
} else {
switch (TimeSetPosition) {
case 0:
tmpValue = year;
tmpMinValue = 15;
tmpMaxValue = 99;
break;
case 1:
tmpValue = month;
tmpMinValue = 1;
tmpMaxValue = 12;
break;
case 2:
tmpValue = dayOfMonth;
tmpMinValue = 1;
tmpMaxValue = 31;
break;
case 3:
tmpValue = hour;
tmpMinValue = 0;
tmpMaxValue = 23;
break;
case 4:
tmpValue = minute;
tmpMinValue = 0;
tmpMaxValue = 59;
break;
}
GLCD.InvertRect(57+(TimeSetPosition*18), highlighthight-2, 14, highlighthight+3);
while (KeepLoop2) {
encCurrentValue = myEnc.read()/4;
if (encCurrentValue != encLastValue) {
tmpValue = tmpValue - (encCurrentValue - encLastValue);
if (tmpValue > tmpMaxValue) {
tmpValue = tmpMaxValue;
}
if (tmpValue < tmpMinValue) {
tmpValue = tmpMinValue;
}
encLastValue = encCurrentValue;
GLCD.CursorToXY(58+(TimeSetPosition*18), highlighthight+1);
GLCD.Printf("%02d", tmpValue);
}
buttonState = digitalRead(Click_Button);
if (buttonState == LOW) { // buttom pressed
while (buttonState == LOW) { // button released
buttonState = digitalRead(Click_Button);
delay(50);
}
KeepLoop2 = false;
}
}
// write the new value back into the correcponding valiable
switch (TimeSetPosition) {
case 0:
year = tmpValue;
break;
case 1:
month = tmpValue;
break;
case 2:
dayOfMonth = tmpValue;
break;
case 3:
hour = tmpValue;
break;
case 4:
minute = tmpValue;
break;
}
GLCD.InvertRect(57+(TimeSetPosition*18), highlighthight-2, 14, highlighthight+3);
KeepLoop2 = true;
}
}
}
// set time here
setDS3231time(00,minute,hour,7,dayOfMonth,month,year);
textAreaSetting1.SetFontColor(PIXEL_OFF);
textAreaSetting1.ClearArea();
textAreaSetting1.print(StringSetting1);
bTimer = 0;
ButtonPush = 0;
KeepLoop1 = true;
}