Files
Arduino/UTFT_MENU/UTFT_MENU.ino
Jérôme Delacotte 7b30d6e298 first commit
2025-03-06 11:15:32 +01:00

1328 lines
34 KiB
C++
Executable File
Raw Permalink Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#include <UTFT.h>
UTFT myGLCD(ITDB32S,38,39,40,41);
// Declare which fonts we will be using
extern uint8_t SmallFont[];
#define TS_MINX 150
#define TS_MINY 120
#define TS_MAXX 920
#define TS_MAXY 940
// Color definitions - in 5:6:5
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
#define TEST 0x1BF5
#define JJCOLOR 0x1CB6
#define JJORNG 0xFD03
int i = 0;
int page = 0;
int blv;
int sleep = 0;
int pulsev = 0;
int redflag = 0;
int greenflag = 0;
int redled = 2;
int greenled = A4;
int backlight = 3;
int battfill;
unsigned long sleeptime;
unsigned long battcheck = 10000; // the amount of time between voltage check and battery icon refresh
unsigned long prevbatt;
int battv;
int battold;
int battpercent;
int barv;
int prevpage;
int sleepnever;
int esleep;
int backlightbox;
int antpos = 278;
unsigned long awakeend;
unsigned long currenttime;
unsigned long ssitime;
char voltage[10];
char battpercenttxt [10];
long readVcc() {
long result;
// Read 1.1V reference against AVcc
ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
delay(2); // Wait for Vref to settle
ADCSRA |= _BV(ADSC); // Convert
while (bit_is_set(ADCSRA,ADSC));
result = ADCL;
result |= ADCH<<8;
result = 1126400L / result; // Back-calculate AVcc in mV
return result;
}
void setup(void) {
pinMode(3, OUTPUT);
pinMode(redled, OUTPUT);
pinMode(greenled, OUTPUT);
//esleep = EEPROM.read(1);
//blv = EEPROM.read(2);
esleep = 3; // uncomment this and run once if you have not used the EEPROM before on your Arduino! Comment and reload after that.
blv = 255; // uncomment this and run once if you have not used the EEPROM before on your Arduino! Comment and reload after that.c
if (esleep == 1) {
sleeptime = 10000;
}
if (esleep == 2) {
sleeptime = 20000;
}
if (esleep == 3) {
sleeptime = 30000;
}
if (esleep == 4) {
sleeptime = 60000;
}
if (esleep == 5) {
sleeptime = 120000;
}
if (esleep == 6) {
sleeptime = 300000;
}
if (esleep == 7) {
sleeptime = 600000;
}
if (esleep == 8) {
sleeptime = 1200000;
}
if (esleep == 9) {
sleeptime = 1800000;
}
if (esleep == 10) {
sleeptime = 3600000;
}
if (esleep == 11) {
sleeptime = 14400000;
}
if (esleep == 12) {
sleepnever = 1;
}
awakeend = sleeptime + 1000; // set the current sleep time based on what the saved settings in EEPROM were
pinMode(backlight, OUTPUT);
Serial.begin(9600);
Serial.println("JOS");
Serial.println("Jeremy Saglimbeni - 2011");
//myGLCD.begin(identifier);
// Setup the LCD
myGLCD.InitLCD();
myGLCD.setFont(SmallFont);
myGLCD.clrScr();
//myGLCD.setRotation(1);
myGLCD.setColor(JJCOLOR);
myGLCD.fillRect(71, 70, 50, 100);
myGLCD.fillRect(134, 70, 50, 100);
myGLCD.fillRect(197, 70, 50, 100);
myGLCD.setColor(WHITE);
myGLCD.drawRect(46, 45, 228, 150);
for(i = 0 ; i <= blv; i+=1) {
analogWrite(backlight, i);
delay(2);
}
delay(250);
// myGLCD.setCursor(85, 100);
//myGLCD.setTextSize(5);
// myGLCD.setTextColor(WHITE);
myGLCD.print("J", 85, 100);
delay(250);
// myGLCD.setCursor(147, 100);
myGLCD.print("O", 147, 100);
delay(250);
//myGLCD.setCursor(210, 100);
myGLCD.print("S", 210, 100);
delay(500);
//myGLCD.setCursor(84, 210);
//myGLCD.setTextSize(1);
myGLCD.print("Jeremy Saglimbeni - 2012", 84, 210);
// myGLCD.setCursor(108, 230);
myGLCD.print("thecustomgeek.com", 108, 230);
delay(500);
cube();
myGLCD.clrScr();
myGLCD.setColor(JJCOLOR);
myGLCD.fillRect(0, 0, 320, 10); // status bar
drawhomeicon(); // draw the home icon
//myGLCD.setCursor(1, 1);
myGLCD.print("Your status bar message here. JOS 1.5 Beta", 1, 1);
myGLCD.setColor(WHITE);
myGLCD.drawRect(297, 1, 20, 8); //battery body
myGLCD.fillRect(317, 3, 2, 4); // battery tip
myGLCD.setColor(BLACK);
myGLCD.fillRect(298, 2, 18, 6); // clear the center of the battery
drawbatt();
ant(); // draw the bas "antenna" line without the "signal waves"
signal(); // draw the "signal waves" around the "antenna"
homescr(); // draw the homescreen
myGLCD.setColor(WHITE);
myGLCD.drawRect(0, 200, 245, 40); // message box
pinMode(13, OUTPUT);
}
#define MINPRESSURE 10
#define MAXPRESSURE 1000
void loop() {
digitalWrite(13, HIGH);
TSPoint p = ts.getPoint();
digitalWrite(13, LOW);
// if you're sharing pins, you'll need to fix the directions of the touchscreen pins!
//pinMode(XP, OUTPUT);
pinMode(XM, OUTPUT);
pinMode(YP, OUTPUT);
//pinMode(YM, OUTPUT);
currenttime = millis();
unsigned long currentawake = millis();
if((currentawake > awakeend) && (sleepnever == 0)) {
if (sleep == 0) {
for(i = blv ; i >= 0; i-=1) {
analogWrite(backlight, i);
delay(4);
}
sleep = 1;
}
}
// we have some minimum pressure we consider 'valid'
// pressure of 0 means no pressing!
if (p.z > MINPRESSURE && p.z < MAXPRESSURE) {
Serial.print("X = ");
Serial.print(p.x);
Serial.print("\tY = ");
Serial.print(p.y);
Serial.print("\tPressure = ");
Serial.println(p.z);
awakeend = currenttime + sleeptime; //set the sleep time when screen is pressed
if (sleep == 1) { // if asleep, then fade the backlight up
for(i = 0 ; i <= blv; i+=1) {
analogWrite(backlight, i);
delay(1);
}
sleep = 0; // change the sleep mode to "awake"
return;
}
// turn from 0->1023 to myGLCD.width
p.x = map(p.x, TS_MINX, TS_MAXX, 240, 0);
p.y = map(p.y, TS_MINY, TS_MAXY, 320, 0);
Serial.print("p.y:"); // this code will help you get the y and x numbers for the touchscreen
Serial.print(p.y);
Serial.print(" p.x:");
Serial.println(p.x);
// area 1
if (p.y > 0 && p.y < 146 && p.x > 178 && p.x < 226) { // if this area is pressed
if (page == 5) { // and if page 5 is drawn on the screen
m5b1action(); // do whatever this button is
//myGLCD.setTextColor(RED);
// myGLCD.setTextSize(2);
// myGLCD.setCursor(12, 213);
myGLCD.print("Menu 5 B1", 12, 213); // display the command in the "message box"
yled(550); // flash the LED yellow for a bit - change the 550 value to change LED time on
clearmessage(); // after the LED goes out, clear the message
}
if (page == 4) {
m4b1action();
// myGLCD.setCursor(12, 213);
myGLCD.print("Menu 4 B1", 12, 213);
yled(550);
clearmessage();
}
if (page == 3) {
m3b1action();
// myGLCD.setCursor(12, 213);
myGLCD.print("Menu 3 B1", 12, 213);
yled(550);
clearmessage();
}
if (page == 2) {
m2b1action();
// myGLCD.setCursor(12, 213);
myGLCD.print("Menu 2 B1", 12, 213);
yled(550);
clearmessage();
}
if (page == 1) {
m1b1action();
// myGLCD.setCursor(12, 213);
myGLCD.print("Menu 1 B1", 12, 213);
yled(550);
clearmessage();
}
if (page == 0) { // if you are on the "home" page (0)
page = 1; // then you just went to the first page
redraw(); // redraw the screen with the page value 1, giving you the page 1 menu
}
}
// area 2
if (p.y > 168 && p.y < 320 && p.x > 180 && p.x < 226) {
if (page == 5) {
m5b2action();
// myGLCD.setCursor(12, 213);
myGLCD.print("Menu 5 B2", 12, 213);
yled(550);
clearmessage();
}
if (page == 4) {
m4b2action();
// myGLCD.setCursor(12, 213);
myGLCD.print("Menu 4 B2", 12, 213);
yled(550);
clearmessage();
}
if (page == 3) {
m3b2action();
// myGLCD.setCursor(12, 213);
myGLCD.print("Menu 3 B2", 12, 213);
yled(550);
clearmessage();
}
if (page == 2) {
m2b2action();
// myGLCD.setCursor(12, 213);
myGLCD.print("Menu 2 B2", 12, 213);
yled(550);
clearmessage();
}
if (page == 1) {
m1b2action();
// myGLCD.setCursor(12, 213);
myGLCD.print("Menu 1 B2", 12, 213);
yled(550);
clearmessage();
}
if (page == 0) {
page = 2;
redraw();
}
}
// area 3
if (p.y > 0 && p.y < 146 && p.x > 120 && p.x < 168) {
if (page == 5) {
m5b3action();
// myGLCD.setCursor(12, 213);
myGLCD.print("Menu 5 B3", 12, 213);
yled(550);
delay(1000);
clearmessage();
}
if (page == 4) {
m4b3action();
// myGLCD.setCursor(12, 213);
myGLCD.print("Menu 4 B3", 12, 213);
yled(550);
clearmessage();
}
if (page == 3) {
m3b3action();
// myGLCD.setCursor(12, 213);
myGLCD.print("Menu 3 B3", 12, 213);
yled(550);
clearmessage();
}
if (page == 2) {
m2b3action();
// myGLCD.setCursor(12, 213);
myGLCD.print("Menu 2 B3", 12, 213);
yled(550);
clearmessage();
}
if (page == 1) {
Serial.println("Menu 1 B3");
m1b3action();
// myGLCD.setCursor(12, 213);
myGLCD.print("Menu 1 B3", 12, 213);
yled(550);
clearmessage();
page = 3;
redraw();
}
if (page == 0) {
page = 3;
redraw();
}
}
// area 4
if (p.y > 167 && p.y < 320 && p.x > 120 && p.x < 168) {
if (page == 5) {
m5b4action();
// myGLCD.setCursor(12, 213);
myGLCD.print("Menu 5 B4", 12, 213);
yled(550);
clearmessage();
}
if (page == 4) {
m4b4action();
// myGLCD.setCursor(12, 213);
myGLCD.print("Menu 4 B4", 12, 213);
yled(550);
clearmessage();
}
if (page == 3) {
m3b4action();
// myGLCD.setCursor(12, 213);
myGLCD.print("Menu 3 B4", 12, 213);
yled(550);
clearmessage();
}
if (page == 2) {
m2b4action();
// myGLCD.setCursor(12, 213);
myGLCD.print("Menu 2 B4", 12, 213);
yled(550);
clearmessage();
}
if (page == 1) {
m1b4action();
// myGLCD.setCursor(12, 213);
myGLCD.print("Menu 1 B4",12, 213);
yled(550);
clearmessage();
}
if (page == 0) {
page = 4;
redraw();
}
}
// area 5
if (p.y > 0 && p.y < 146 && p.x > 54 && p.x < 104) {
if (page == 5) {
m5b5action();
// myGLCD.setCursor(12, 213);
myGLCD.print("Menu 5 B5", 12, 213);
yled(550);
clearmessage();
}
if (page == 4) {
m4b5action();
// myGLCD.setCursor(12, 213);
myGLCD.print("Menu 4 B5", 12, 213);
yled(550);
clearmessage();
}
if (page == 3) {
m3b5action();
// myGLCD.setCursor(12, 213);
myGLCD.print("Menu 3 B5", 12, 213);
yled(550);
clearmessage();
}
if (page == 2) {
m2b5action();
// myGLCD.setCursor(12, 213);
myGLCD.print("Menu 2 B5", 12, 213);
yled(550);
clearmessage();
}
if (page == 1) {
m1b5action();
// myGLCD.setCursor(12, 213);
myGLCD.print("Menu 1 B5", 12, 213);
yled(550);
clearmessage();
}
if (page == 0) {
page = 5;
redraw();
}
}
// area 6
if (p.y > 168 && p.y < 320 && p.x > 54 && p.x < 104) {
if (page == 5) {
m5b6action();
// myGLCD.setCursor(12, 213);
myGLCD.print("Menu 5 B6", 12, 213);
yled(550);
clearmessage();
}
if (page == 4) {
m4b6action();
// myGLCD.setCursor(12, 213);
myGLCD.print("Menu 4 B6", 12, 213);
yled(550);
clearmessage();
}
if (page == 3) {
m3b6action();
// myGLCD.setCursor(12, 213);
myGLCD.print("Menu 3 B6", 12, 213);
yled(550);
clearmessage();
}
if (page == 2) {
m2b6action();
// myGLCD.setCursor(12, 213);
myGLCD.print("Menu 2 B6", 12, 213);
yled(550);
clearmessage();
}
if (page == 1) {
m1b6action();
// // myGLCD.setCursor(12, 213);
myGLCD.print("Menu 1 B6", 12, 213);
yled(550);
clearmessage();
}
if (page == 0) {
page = 6;
redraw();
}
}
// home
if (p.y > 280 && p.y < 340 && p.x > 0 && p.x < 48) { // if the home icon is pressed
if (page == 6) { // if you are leaving the settings page
clearmessage(); // clear the battery voltage out of the message box
//myGLCD.setTextSize(2);
// myGLCD.setTextColor(YELLOW);
//// myGLCD.setCursor(12, 213);
myGLCD.print("Settings Saved", 12, 213); // display settings saved in message box
/*
EEPROM.write(1, esleep); // write the sleep value to EEPROM, so it will not lose settings without power
EEPROM.write(2, blv); // write the backlight value to EEPROM, so it will not lose settings without power
*/
clearsettings(); // erase all the drawings on the settings page
}
if (page == 0) { // if you are already on the home page
drawhomeiconred(); // draw the home icon red
delay(250); // wait a bit
drawhomeicon(); // draw the home icon back to white
return; // if you were on the home page, stop.
}
else { // if you are not on the settings, home, or keyboard page
page = prevpage; // a value to keep track of what WAS on the screen to redraw/erase only what needs to be
page = 0; // make the current page home
redraw(); // redraw the page
}
}
// message area
if (p.y > 0 && p.y < 246 && p.x > 4 && p.x < 44) {
clearmessage(); // erase the message
}
// backlight buttons
if (p.y > 0 && p.y < 56 && p.x > 176 && p.x < 226) {
if (page == 6) {
blightdown();
}
}
if (p.y > 260 && p.y < 320 && p.x > 180 && p.x < 230) {
if (page == 6) {
blightup();
}
}
// sleep buttons
if (p.y > 0 && p.y < 56 && p.x > 116 && p.x < 166) {
if (page == 6) {
sleepdec();
}
}
if (p.y > 260 && p.y < 320 && p.x > 116 && p.x < 166) {
if (page == 6) {
sleepinc();
}
}
/*
// optional buttons
if (p.y > 3 && p.y < 66 && p.x > 72 && p.x < 126) {
if (page == 6) {
option3down();
}
}
if (p.y > 269 && p.y < 324 && p.x > 72 && p.x < 126) {
if (page == 6) {
option3up();
}
}
*/
}
if(currenttime - prevbatt > battcheck) {
drawbatt();
prevbatt = currenttime;
}
}
void yled(int xled) { // "flashes" the "yellow" LED
for(i = xled ; i >= 0; i-=1) {
digitalWrite(greenled, LOW);
digitalWrite(redled, HIGH);
delay(1);
digitalWrite(greenled, HIGH);
digitalWrite(redled, LOW);
delay(1);
}
digitalWrite(greenled, LOW);
if (greenflag == 1) {
digitalWrite(redled, LOW);
digitalWrite(greenled, HIGH);
}
if (redflag == 1) {
digitalWrite(greenled, LOW);
digitalWrite(redled, HIGH);
}
}
void redraw() { // redraw the page
if ((prevpage != 6) || (page !=7)) {
clearcenter();
}
if (page == 0) {
homescr();
}
if (page == 1) {
menu1();
}
if (page == 2) {
menu2();
}
if (page == 3) {
menu3();
}
if (page == 4) {
menu4();
}
if (page == 5) {
menu5();
}
if (page == 6) {
settingsscr();
}
}
void clearcenter() { // the reason for so many small "boxes" is that it's faster than filling the whole thing
myGLCD.drawRect(0, 20, 150, 50, BLACK);
myGLCD.drawRect(170, 20, 150, 50, BLACK);
myGLCD.drawRect(0, 80, 150, 50, BLACK);
myGLCD.drawRect(170, 80, 150, 50, BLACK);
myGLCD.drawRect(0, 140, 150, 50, BLACK);
myGLCD.drawRect(170, 140, 150, 50, BLACK);
myGLCD.setColor(BLACK);
myGLCD.fillRect(22, 37, 106, 16);
myGLCD.fillRect(192, 37, 106, 16);
myGLCD.fillRect(22, 97, 106, 16);
myGLCD.fillRect(192, 97, 106, 16);
myGLCD.fillRect(22, 157, 106, 16);
myGLCD.fillRect(192, 157, 106, 16);
}
void clearsettings() { // this is used to erase the extra drawings when exiting the settings page
myGLCD.setColor(BLACK);
myGLCD.fillRect(0, 20, 320, 110);
delay(500);
clearmessage();
}
void homescr() {
//myGLCD.setTextColor(WHITE);
// myGLCD.setTextSize(2);
boxes();
// myGLCD.setCursor(41, 37);
myGLCD.print("Menu 1", 41, 37);
// myGLCD.setCursor(210, 37);
myGLCD.print("Menu 2", 210, 37);
// myGLCD.setCursor(41, 97);
myGLCD.print("Menu 3", 41, 97);
// myGLCD.setCursor(210, 97);
myGLCD.print("Menu 4", 210, 97);
// myGLCD.setCursor(41, 157);
myGLCD.print("Menu 5", 41, 157);
// myGLCD.setCursor(200, 157);
myGLCD.print("Settings", 200, 157);
}
void menu1() {
//myGLCD.setTextColor(WHITE);
// myGLCD.setTextSize(2);
boxes();
// myGLCD.setCursor(22, 37);
myGLCD.print("Menu 1 B1", 22, 37);
// myGLCD.setCursor(192, 37);
myGLCD.print("Menu 1 B2", 192, 37);
// myGLCD.setCursor(22, 97);
myGLCD.print("Menu 1 B3", 22, 97);
// myGLCD.setCursor(192, 97);
myGLCD.print("Menu 1 B4", 192, 97);
// myGLCD.setCursor(22, 157);
myGLCD.print("Menu 1 B5", 22, 157);
// myGLCD.setCursor(192, 157);
myGLCD.print("Menu 1 B6", 192, 157);
}
void menu2() {
//myGLCD.setTextColor(WHITE);
// myGLCD.setTextSize(2);
boxes();
//myGLCD.setCursor(22, 37);
myGLCD.print("Menu 2 B1", 22, 37);
//myGLCD.setCursor(192, 37);
myGLCD.print("Menu 2 B2", 192, 37);
//myGLCD.setCursor(22, 97);
myGLCD.print("Menu 2 B3", 22, 97);
//myGLCD.setCursor(192, 97);
myGLCD.print("Menu 2 B4", 192, 97);
//myGLCD.setCursor(22, 157);
myGLCD.print("Menu 2 B5", 22, 157);
//myGLCD.setCursor(192, 157);
myGLCD.print("Menu 2 B6", 192, 157);
}
void menu3() {
//myGLCD.setTextColor(WHITE);
//myGLCD.setTextSize(2);
boxes();
//myGLCD.setCursor(22, 37);
myGLCD.print("Menu 3 B1", 22, 37);
//myGLCD.setCursor(192, 37);
myGLCD.print("Menu 3 B2", 192, 37);
//myGLCD.setCursor(22, 97);
myGLCD.print("Menu 3 B3", 22, 97);
//myGLCD.setCursor(192, 97);
myGLCD.print("Menu 3 B4", 192, 97);
//myGLCD.setCursor(22, 157);
myGLCD.print("Menu 3 B5", 22, 157);
// myGLCD.setCursor(192, 157);
myGLCD.print("Menu 3 B6",192, 157);
}
void menu4() {
//myGLCD.setTextColor(WHITE);
//myGLCD.setTextSize(2);
boxes();
//myGLCD.setCursor(22, 37);
myGLCD.print("Menu 4 B1", 22, 37);
//myGLCD.setCursor(192, 37);
myGLCD.print("Menu 4 B2", 192, 37);
// myGLCD.setCursor(22, 97);
myGLCD.print("Menu 4 B3", 22, 97);
// myGLCD.setCursor(192, 97);
myGLCD.print("Menu 4 B4", 192, 97);
//myGLCD.setCursor(22, 157);
myGLCD.print("Menu 4 B5", 22, 157);
// myGLCD.setCursor(192, 157);
myGLCD.print("Menu 4 B6", 192, 157);
}
void menu5() {
// myGLCD.setTextColor(WHITE);
// myGLCD.setTextSize(2);
boxes();
// myGLCD.setCursor(22, 37);
myGLCD.print("Menu 5 B1", 22, 37);
// myGLCD.setCursor(192, 37);
myGLCD.print("Menu 5 B2", 192, 37);
// myGLCD.setCursor(22, 97);
myGLCD.print("Menu 5 B3", 22, 97);
// myGLCD.setCursor(192, 97);
myGLCD.print("Menu 5 B4", 192, 97);
// myGLCD.setCursor(22, 157);
myGLCD.print("Menu 5 B5", 22, 157);
// myGLCD.setCursor(192, 157);
myGLCD.print("Menu 5 B6", 192, 157);
}
void settingsscr() {
// backlight level
//myGLCD.setTextColor(WHITE);
//myGLCD.setTextSize(3);
myGLCD.setColor(RED);
myGLCD.fillRect(0, 20, 60, 50);
myGLCD.setColor(WHITE);
myGLCD.drawRect(0, 20, 60, 50);
myGLCD.drawRect(80, 20, 160, 50, JJCOLOR);
myGLCD.setColor(GREEN);
myGLCD.fillRect(260, 20, 60, 50);
myGLCD.setColor(WHITE);
myGLCD.drawRect(260, 20, 60, 50);
//myGLCD.setCursor(22, 33);
myGLCD.print("-", 22, 33);
// myGLCD.setCursor(282, 33);
myGLCD.print("+", 282, 33);
// myGLCD.setTextSize(1);
// myGLCD.setCursor(120, 31);
myGLCD.print("Backlight Level", 120, 31);
myGLCD.setColor(WHITE);
myGLCD.drawRect(110, 48, 100, 10);
blbar();
// sleep time
//myGLCD.setTextSize(3);
myGLCD.setColor(RED);
myGLCD.fillRect(0, 80, 60, 50);
myGLCD.setColor(WHITE);
myGLCD.drawRect(0, 80, 60, 50);
myGLCD.drawRect(80, 80, 160, 50, JJCOLOR);
myGLCD.setColor(GREEN);
myGLCD.fillRect(260, 80, 60, 50);
myGLCD.setColor(WHITE);
myGLCD.drawRect(260, 80, 60, 50);
// myGLCD.setCursor(22, 93);
myGLCD.print("-", 22, 93);
// myGLCD.setCursor(282, 93);
myGLCD.print("+", 282, 93);
//myGLCD.setTextSize(1);
//myGLCD.setCursor(130, 91);
myGLCD.print("Sleep Time", 130, 91);
showsleep();
//?? uncomment this if you want a third adjustable option
/*
myGLCD.fillRect(0, 140, 60, 50, RED);
myGLCD.drawRect(0, 140, 60, 50, WHITE);
myGLCD.drawRect(80, 140, 160, 50, JJCOLOR);
myGLCD.fillRect(260, 140, 60, 50, GREEN);
myGLCD.drawRect(260, 140, 60, 50, WHITE);
myGLCD.print(22, 153, "-", WHITE, 3);
myGLCD.print(130, 151, "Thing #3", WHITE);
myGLCD.print(282, 153, "+", WHITE, 3);
myGLCD.drawRect(110, 168, 100, 10, WHITE);
*/
battv = readVcc(); // read the voltage
itoa (battv, voltage, 10);
//myGLCD.setTextColor(YELLOW);
// myGLCD.setTextSize(2);
// // myGLCD.setCursor(12, 213);
myGLCD.print(voltage, 12, 213);
// myGLCD.setCursor(60, 213);
myGLCD.print("mV", 60, 213);
/*
battpercent = (battv / 5000) * 100, 2;
itoa (battpercent, battpercenttxt, 10);
myGLCD.print(102, 213, battpercenttxt, YELLOW, 2);
*/
}
void sleepinc() { // sleep increese adjustment
if (sleeptime == 14400000) {
sleepnever = 1;
esleep = 12;
sleeptime = 11111111;
showsleep();
}
if (sleeptime == 3600000) {
sleeptime = 14400000;
esleep = 11;
showsleep();
}
if (sleeptime == 1800000) {
sleeptime = 3600000;
esleep = 10;
showsleep();
}
if (sleeptime == 1200000) {
sleeptime = 1800000;
esleep = 9;
showsleep();
}
if (sleeptime == 600000) {
sleeptime = 1200000;
esleep = 8;
showsleep();
}
if (sleeptime == 300000) {
sleeptime = 600000;
esleep = 7;
showsleep();
}
if (sleeptime == 120000) {
sleeptime = 300000;
esleep = 6;
showsleep();
}
if (sleeptime == 60000) {
sleeptime = 120000;
esleep = 5;
showsleep();
}
if (sleeptime == 30000) {
sleeptime = 60000;
esleep = 4;
showsleep();
}
if (sleeptime == 20000) {
sleeptime = 30000;
esleep = 3;
showsleep();
}
if (sleeptime == 10000) {
sleeptime = 20000;
esleep = 2;
showsleep();
}
delay(350);
}
void sleepdec() { // sleep decreese adjustment
if (sleeptime == 20000) {
sleeptime = 10000;
esleep = 1;
showsleep();
}
if (sleeptime == 30000) {
sleeptime = 20000;
esleep = 2;
showsleep();
}
if (sleeptime == 60000) {
sleeptime = 30000;
esleep = 3;
showsleep();
}
if (sleeptime == 120000) {
sleeptime = 60000;
esleep = 4;
showsleep();
}
if (sleeptime == 300000) {
sleeptime = 120000;
esleep = 5;
showsleep();
}
if (sleeptime == 600000) {
sleeptime = 300000;
esleep = 6;
showsleep();
}
if (sleeptime == 1200000) {
sleeptime = 600000;
esleep = 7;
showsleep();
}
if (sleeptime == 1800000) {
sleeptime = 1200000;
esleep = 8;
showsleep();
}
if (sleeptime == 3600000) {
sleeptime = 1800000;
esleep = 9;
showsleep();
}
if (sleeptime == 14400000) {
sleeptime = 3600000;
esleep = 10;
showsleep();
}
if (sleepnever == 1) {
sleeptime = 14400000;
sleepnever = 0;
esleep = 11;
showsleep();
}
delay(350);
}
void showsleep() { // shows the sleep time on the settings page
myGLCD.setColor(BLACK);
myGLCD.fillRect(110, 108, 80, 10);
//myGLCD.setTextSize(1);
//myGLCD.setTextColor(WHITE);
if (sleeptime == 10000) {
//myGLCD.setCursor(130, 108);
myGLCD.print("10 Seconds", , 130, 108);
}
if (sleeptime == 20000) {
//myGLCD.setCursor(130, 108);
myGLCD.print("20 Seconds", 130, 108);
}
if (sleeptime == 30000) {
//myGLCD.setCursor(130, 108);
myGLCD.print("30 Seconds", 130, 108);
}
if (sleeptime == 60000) {
// myGLCD.setCursor(136, 108);
myGLCD.print("1 Minute", 136, 108);
}
if (sleeptime == 120000) {
//myGLCD.setCursor(133, 108);
myGLCD.print("2 Minutes", 133, 108);
}
if (sleeptime == 300000) {
//myGLCD.setCursor(133, 108);
myGLCD.print("5 Minutes", 133, 108);
}
if (sleeptime == 600000) {
//myGLCD.setCursor(130, 108);
myGLCD.print("10 Minutes", 130, 108);
}
if (sleeptime == 1200000) {
//myGLCD.setCursor(130, 108);
myGLCD.print("20 Minutes", 130, 108);
}
if (sleeptime == 1800000) {
//myGLCD.setCursor(130, 108);
myGLCD.print("30 Minutes", 130, 108);
}
if (sleeptime == 3600000) {
// myGLCD.setCursor(142, 108);
myGLCD.print("1 Hour", 142, 108);
}
if (sleeptime == 14400000) {
// myGLCD.setCursor(139, 108);
myGLCD.print("4 Hours",139, 108);
}
if (sleepnever == 1) {
//myGLCD.setCursor(133, 108);
myGLCD.print("Always On",133, 108);
}
}
void option3down() { // adjust option 3 down in the settings screen
}
void option3up() { // adjust option 3 up in the settings screen
}
//custom defined actions - this is where you put your button functions
void m1b1action() {
signal();
}
void m1b2action() {
signalact();
}
void m1b3action() {
cube();
}
void m1b4action() {
}
void m1b5action() {
}
void m1b6action() {
}
void m2b1action() {
}
void m2b2action() {
}
void m2b3action() {
}
void m2b4action() {
}
void m2b5action() {
}
void m2b6action() {
}
void m3b1action() {
}
void m3b2action() {
}
void m3b3action() {
}
void m3b4action() {
}
void m3b5action() {
}
void m3b6action() {
}
void m4b1action() {
}
void m4b2action() {
}
void m4b3action() {
}
void m4b4action() {
}
void m4b5action() {
}
void m4b6action() {
}
void m5b1action() {
}
void m5b2action() {
}
void m5b3action() {
}
void m5b4action() {
}
void m5b5action() {
}
void m5b6action() {
}
void blightup() { // increase the backlight brightness
blv = blv + 5;
if (blv >= 255) {
blv = 255;
}
analogWrite(backlight, blv);
blbar();
}
void blightdown() { // decrease the backlight brightness
blv = blv - 5;
if (blv <= 5) {
blv = 5;
}
analogWrite(backlight, blv);
blbar();
}
void blbar() { // this function fills the yellow bar in the backlight brightness adjustment
if (blv < barv) {
myGLCD.setColor(BLACK);
myGLCD.fillRect(111, 49, 98, 8);
}
backlightbox = map(blv, 1, 255, 0, 98);
myGLCD.fillRect(111, 49, backlightbox, 8, YELLOW);
barv = blv;
delay(25);
}
void ant() {
myGLCD.setColor(WHITE);
myGLCD.fillRect((antpos + 5), 4, 1, 6); // draws the "antenna" for the signal indicator
}
void boxes() { // redraw the button outline boxes
myGLCD.drawRect(0, 20, 150, 50, JJCOLOR);
myGLCD.drawRect(170, 20, 150, 50, JJCOLOR);
myGLCD.drawRect(0, 80, 150, 50, JJCOLOR);
myGLCD.drawRect(170, 80, 150, 50, JJCOLOR);
myGLCD.drawRect(0, 140, 150, 50, JJCOLOR);
myGLCD.drawRect(170, 140, 150, 50, JJCOLOR);
}
void signal() { // draws a whit 'signal indicator'
myGLCD.drawLine((antpos + 4), 4, (antpos + 4), 5, WHITE);
myGLCD.drawPixel((antpos + 3), 2, WHITE);
myGLCD.drawPixel((antpos + 3), 7, WHITE);
myGLCD.drawPixel((antpos + 2), 0, WHITE);
myGLCD.drawLine((antpos + 2), 3, (antpos + 2), 6, WHITE);
myGLCD.drawPixel((antpos + 2), 9, WHITE);
myGLCD.drawPixel((antpos + 1), 1, WHITE);
myGLCD.drawPixel((antpos + 1), 8, WHITE);
myGLCD.drawLine(antpos, 2, antpos, 7, WHITE);
myGLCD.drawLine((antpos + 6), 4, (antpos + 6), 5, WHITE);
myGLCD.drawPixel((antpos + 7), 2, WHITE);
myGLCD.drawPixel((antpos + 7), 7, WHITE);
myGLCD.drawPixel((antpos + 8), 0, WHITE);
myGLCD.drawLine((antpos + 8), 3, (antpos + 8), 6, WHITE);
myGLCD.drawPixel((antpos + 8), 9, WHITE);
myGLCD.drawPixel((antpos + 9), 1, WHITE);
myGLCD.drawPixel((antpos + 9), 8, WHITE);
myGLCD.drawLine((antpos + 10), 2, (antpos + 10), 7, WHITE);
}
void signalact() { // draws a red'signal indicator'
myGLCD.drawLine((antpos + 4), 4, (antpos + 4), 5, RED);
myGLCD.drawPixel((antpos + 3), 2, RED);
myGLCD.drawPixel((antpos + 3), 7, RED);
myGLCD.drawPixel((antpos + 2), 0, RED);
myGLCD.drawLine((antpos + 2), 3, (antpos + 2), 6, RED);
myGLCD.drawPixel((antpos + 2), 9, RED);
myGLCD.drawPixel((antpos + 1), 1, RED);
myGLCD.drawPixel((antpos + 1), 8, RED);
myGLCD.drawLine(antpos, 2, antpos, 7, RED);
myGLCD.drawLine((antpos + 6), 4, (antpos + 6), 5, RED);
myGLCD.drawPixel((antpos + 7), 2, RED);
myGLCD.drawPixel((antpos + 7), 7, RED);
myGLCD.drawPixel((antpos + 8), 0, RED);
myGLCD.drawLine((antpos + 8), 3, (antpos + 8), 6, RED);
myGLCD.drawPixel((antpos + 8), 9, RED);
myGLCD.drawPixel((antpos + 9), 1, RED);
myGLCD.drawPixel((antpos + 9), 8, RED);
myGLCD.drawLine((antpos + 10), 2, (antpos + 10), 7, RED);
}
void drawhomeicon() { // draws a white home icon
myGLCD.drawLine(280, 219, 299, 200, WHITE);
myGLCD.drawLine(300, 200, 304, 204, WHITE);
myGLCD.drawLine(304, 203, 304, 200, WHITE);
myGLCD.drawLine(305, 200, 307, 200, WHITE);
myGLCD.drawLine(308, 200, 308, 208, WHITE);
myGLCD.drawLine(309, 209, 319, 219, WHITE);
myGLCD.drawLine(281, 219, 283, 219, WHITE);
myGLCD.drawLine(316, 219, 318, 219, WHITE);
myGLCD.setColor(WHITE);
myGLCD.drawRect(284, 219, 32, 21);
myGLCD.drawRect(295, 225, 10, 15);
}
void drawhomeiconred() { // draws a red home icon
myGLCD.drawLine(280, 219, 299, 200, RED);
myGLCD.drawLine(300, 200, 304, 204, RED);
myGLCD.drawLine(304, 203, 304, 200, RED);
myGLCD.drawLine(305, 200, 307, 200, RED);
myGLCD.drawLine(308, 200, 308, 208, RED);
myGLCD.drawLine(309, 209, 319, 219, RED);
myGLCD.drawLine(281, 219, 283, 219, RED);
myGLCD.drawLine(316, 219, 318, 219, RED);
myGLCD.setColor(RED);
myGLCD.drawRect(284, 219, 32, 21);
myGLCD.drawRect(295, 225, 10, 15);
}
void clearmessage() {
myGLCD.setColor(BLACK);
myGLCD.fillRect(12, 213, 226, 16); // black out the inside of the message box
}
void drawbatt() {
battv = readVcc(); // read the voltage
if (battv < battold) { // if the voltage goes down, erase the inside of the battery
myGLCD.setColor(BLACK);
myGLCD.fillRect(298, 2, 18, 6);
}
battfill = map(battv, 3000, 4850, 2, 18); // map the battery voltage 3000 nis the low, 4150 is the high
if (battfill > 7) { // if the battfill value is between 8 and 18, fill with green
myGLCD.setColor(GREEN);
myGLCD.fillRect(298, 2, battfill, 6);
}
else { // if the battfill value is below 8, fill with red
myGLCD.setColor(RED);
myGLCD.fillRect(298, 2, battfill, 6);
}
battold = battv; // this helps determine if redrawing the battfill area is necessary
}
///////// CUBE ///////////////////
typedef struct
{
int x,y;
} point;
int key;
float a=0.0,b=0.0;
//float ax,ay,az;
short lx[8]={1,1,1,1,-1,-1,-1,-1};
short ly[8]={1,1,-1,-1,1,1,-1,-1};
short lz[8]={1,-1,1,-1,1,-1,1,-1};
float lxn[8],lyn[8],lzn[8];
float xd[8],yd[8];
float c=1.0;
float xt,yt,zt;
float mr[3][3];
float znm;
int face[6][4]={{4,0,1,5},{1,0,2,3},{5,1,3,7},{4,5,7,6},{0,4,6,2},{3,2,6,7}};
int facec[6]={10,20,30,20,30,10};
point points[10];
// Quick sort
int tri[12];
int zface[12];
void QuickSort(int deb, int fin)
{
int i=deb;
int j=fin;
double milieu=256*zface[tri[(deb+fin)/2]];
int temp;
while(i<=j)
{
while(256*zface[tri[i]]> milieu) i++;
while(256*zface[tri[j]]< milieu) j--;
if(i<=j)
{
temp=tri[i];
tri[i]=tri[j];
tri[j]=temp;
i++; j--;
}
}
if(i<fin) QuickSort(i,fin);
if(deb<j) QuickSort(deb,j);
// draw();
}
void cube() {
myGLCD.clrScr();
Serial.println("Dans cube");
for (int i = 0; i <360;i+=5) {
delay(100);
Serial.println(i);
//TSPoint p = ts.getPoint();
//
// we have some minimum pressure we consider 'valid'
// pressure of 0 means no pressing!
//if (p.z > ts.pressureThreshhold) {
a=a-0.05;
b=b+0.05;
for(int n=0;n<8;n++) {
lxn[n]=lx[n]*cos(b)+ly[n]*sin(a)*sin(b)+lz[n]*cos(a)*sin(b);
lyn[n]=ly[n]*cos(a)-lz[n]*sin(a);
lzn[n]=-lx[n]*sin(b)+ly[n]*sin(a)*cos(b)+lz[n]*cos(a)*cos(b)+5;
xd[n]=(240/2)+(240*lxn[n]*c)/(2*lzn[n]);
yd[n]=(320/2)+(320*lyn[n]*c)/(2*lzn[n]);
}
int facev=0;
for(int m=0;m<6;m++) {
znm=(xd[face[m][2]]-xd[face[m][1]])*(yd[face[m][1]]-yd[face[m][3]])-(yd[face[m][2]]-yd[face[m][1]])*(xd[face[m][1]]-xd[face[m][3]]);
//znm=2; only zsorting
if(znm>0) {
zface[m]=lzn[face[m][0]]+lzn[face[m][1]]+lzn[face[m][2]]+lzn[face[m][3]]+lzn[face[m][4]];
tri[facev]=m;
facev++;
}
}
QuickSort(0,facev-1);
//myGLCD.clrScr();
//for(int mb=0;mb<6;mb++) {
for(int mb=0;mb<facev;mb++) {
int color = WHITE;
switch (tri[mb]) {
case 0:
color = WHITE;
break;
case 1:
color = RED;
break;
case 2:
color = BLUE;
break;
case 3:
color = YELLOW;
break;
case 4:
color = GREEN;
break;
case 5:
color = CYAN;
break;
default:
break;
}
points[0].x = xd[face[tri[mb]][0]];
points[0].y = yd[face[tri[mb]][0]];
points[1].x = xd[face[tri[mb]][1]];
points[1].y = yd[face[tri[mb]][1]];
points[2].x = xd[face[tri[mb]][2]];
points[2].y = yd[face[tri[mb]][2]];
points[3].x = xd[face[tri[mb]][3]];
points[3].y = yd[face[tri[mb]][3]];
// FACE 1
myGLCD.setColor(color);
myGLCD.drawLine(
points[0].x, points[0].y,
points[1].x, points[1].y);
myGLCD.drawLine(
points[1].x, points[1].y,
points[2].x, points[2].y);
myGLCD.drawLine(
points[2].x, points[2].y,
points[3].x, points[3].y);
myGLCD.drawLine(
points[3].x, points[3].y,
points[0].x, points[0].y);
//delay(500);
//myGLCD.fillTriangle(points[1].x,points[1].y,points[2].x,points[2].y,points[3].x,points[3].y,WHITE);
// myGLCD.fillTriangle(xd[3],yd[3],xd[4],yd[4],xd[1],yd[1], WHITE);
//FillPoly(points,4,facec[mb]);
}
}
}