2 of 2
Try not to laugh too much at this...
void drawKeypad () {
clear();
TopTXT();
PassTXT();
one_btn.initButton(&tft, 55, 93, 50, 50, BLACK, LTBL, BG333, "1", 1);
two_btn.initButton(&tft, 120, 93, 50, 50, BLACK, LTBL, BG333, "2", 1);
three_btn.initButton(&tft, 185, 93, 50, 50, BLACK, LTBL, BG333, "3", 1);
four_btn.initButton(&tft, 55, 158, 50, 50, BLACK, LTBL, BG333, "4", 1);
five_btn.initButton(&tft, 120, 158, 50, 50, BLACK, LTBL, BG333, "5", 1);
six_btn.initButton(&tft, 185, 158, 50, 50, BLACK, LTBL, BG333, "6", 1);
seven_btn.initButton(&tft, 55, 223, 50, 50, BLACK, LTBL, BG333, "7", 1);
eight_btn.initButton(&tft, 120, 223, 50, 50, BLACK, LTBL, BG333, "8", 1);
nine_btn.initButton(&tft, 185, 223, 50, 50, BLACK, LTBL, BG333, "9", 1);
clear_btn.initButton(&tft, 55, 288, 50, 50, BLACK, LTBL, BG333, "CLR", 1);
zero_btn.initButton(&tft, 120, 288, 50, 50, BLACK, LTBL, BG333, "0", 1);
call_btn.initButton(&tft, 185, 288, 50, 50, BLACK, LTBL, BG333, "CALL", 1);
one_btn.drawButton(false);
two_btn.drawButton(false);
three_btn.drawButton(false);
four_btn.drawButton(false);
five_btn.drawButton(false);
six_btn.drawButton(false);
seven_btn.drawButton(false);
eight_btn.drawButton(false);
nine_btn.drawButton(false);
clear_btn.drawButton(false);
zero_btn.drawButton(false);
call_btn.drawButton(false);
}
void drawCallpad() {
clear();
return1_btn.initButton(&tft, 185, 288, 50, 50, BLACK, LTBL, BG333, "Back", 1);
return1_btn.drawButton(false);
}
void clear() {
tft.fillScreen(BG222);
}
void showmsgXY(int x, int y, int sz, const GFXfont *f, const char *msg, int clr)
{
int16_t x1, y1;
uint16_t wid, ht;
// tft.drawFastHLine(0, y, tft.width(), WHITE);
tft.setFont(f);
tft.setCursor(x, y);
tft.setTextColor(clr);
tft.setTextSize(sz);
tft.print(msg);
}
void loop() {
while (keyScrn) {
keypad();
}
while (callScrn) {
callpad();
}
}
void keypad(void)
{
bool down = Touch_getXY();
one_btn.press(down && one_btn.contains(pixel_x, pixel_y));
two_btn.press(down && two_btn.contains(pixel_x, pixel_y));
three_btn.press(down && three_btn.contains(pixel_x, pixel_y));
four_btn.press(down && four_btn.contains(pixel_x, pixel_y));
five_btn.press(down && five_btn.contains(pixel_x, pixel_y));
six_btn.press(down && six_btn.contains(pixel_x, pixel_y));
seven_btn.press(down && seven_btn.contains(pixel_x, pixel_y));
eight_btn.press(down && eight_btn.contains(pixel_x, pixel_y));
nine_btn.press(down && nine_btn.contains(pixel_x, pixel_y));
clear_btn.press(down && clear_btn.contains(pixel_x, pixel_y));
zero_btn.press(down && zero_btn.contains(pixel_x, pixel_y));
call_btn.press(down && call_btn.contains(pixel_x, pixel_y));
if (one_btn.justReleased())
one_btn.drawButton();
if (two_btn.justReleased())
two_btn.drawButton();
if (three_btn.justReleased())
three_btn.drawButton();
if (four_btn.justReleased())
four_btn.drawButton();
if (five_btn.justReleased())
five_btn.drawButton();
if (six_btn.justReleased())
six_btn.drawButton();
if (seven_btn.justReleased())
seven_btn.drawButton();
if (eight_btn.justReleased())
eight_btn.drawButton();
if (nine_btn.justReleased())
nine_btn.drawButton();
if (clear_btn.justReleased())
clear_btn.drawButton();
if (zero_btn.justReleased())
zero_btn.drawButton();
if (call_btn.justReleased())
call_btn.drawButton();
if (one_btn.justPressed()) {
one_btn.drawButton(true);
tft.fillRect(40, 8, 160, 4, BLACK);
counter++;
Serial.println(counter);
Serial.println("1");
pString += 1;
Serial.println(pString);
checkPword();
delay(100);}
if (two_btn.justPressed()) {
two_btn.drawButton(true);
tft.fillRect(40, 8, 160, 4, BLUE);
counter++;
Serial.println(counter);
Serial.println("2");
pString += 2;
Serial.println(pString);
checkPword();
delay(100);}
if (three_btn.justPressed()) {
three_btn.drawButton(true);
tft.fillRect(40, 8, 160, 4, RED);
counter++;
Serial.println(counter);
Serial.println("3");
pString += 3;
Serial.println(pString);
checkPword();
delay(100);}
if (four_btn.justPressed()) {
four_btn.drawButton(true);
tft.fillRect(40, 8, 160, 4, GREEN);
counter++;
Serial.println(counter);
Serial.println("4");
pString += 4;
Serial.println(pString);
checkPword();
delay(100);}
if (five_btn.justPressed()) {
five_btn.drawButton(true);
tft.fillRect(40, 8, 160, 4, CYAN);
counter++;
Serial.println(counter);
Serial.println("5");
pString += 5;
Serial.println(pString);
checkPword();
delay(100);}
if (six_btn.justPressed()) {
six_btn.drawButton(true);
tft.fillRect(40, 8, 160, 4, MAGENTA);
counter++;
Serial.println(counter);
Serial.println("6");
pString += 6;
Serial.println(pString);
checkPword();
delay(100);}
if (seven_btn.justPressed()) {
seven_btn.drawButton(true);
tft.fillRect(40, 8, 160, 4, YELLOW);
counter++;
Serial.println(counter);
Serial.println("7");
pString += 7;
Serial.println(pString);
checkPword();
delay(100);}
if (eight_btn.justPressed()) {
eight_btn.drawButton(true);
tft.fillRect(40, 8, 160, 4, WHITE);
counter++;
Serial.println(counter);
Serial.println("8");
pString += 8;
Serial.println(pString);
checkPword();
delay(100);}
if (nine_btn.justPressed()) {
nine_btn.drawButton(true);
tft.fillRect(40, 8, 160, 4, BLACK);
counter++;
Serial.println(counter);
Serial.println("9");
pString += 9;
Serial.println(pString);
checkPword();
delay(100);}
if (clear_btn.justPressed()) {
clear_btn.drawButton(true);
tft.fillRect(40, 8, 160, 4, GREEN);
counter = 0;
Serial.println(counter);
Serial.println("CLEAR");
pString = "";
Serial.println(pString);
delay(100);}
if (zero_btn.justPressed()) {
zero_btn.drawButton(true);
tft.fillRect(40, 8, 160, 4, YELLOW);
counter++;
Serial.println(counter);
Serial.println("0");
pString += 0;
Serial.println(pString);
checkPword();
delay(100);}
if (call_btn.justPressed()) {
call_btn.drawButton(true);
tft.fillRect(40, 8, 160, 4, RED);
Serial.println("CALL");
counter = 0;
pString = "";
delay(100);
callScrn = true;
keyScrn = false;
drawCallpad();
}
}
void checkPword() {
if (counter == 5) {
if (pString == pWord) {
counter = 0;
correctP = true;
pString = "";
Serial.println("Correct Password Entered");
} else {
counter = 0;
correctP = false;
pString = "";
Serial.println("Incorrect Password Entered");
}
}
}
void callpad(void) {
bool down = Touch_getXY();
return1_btn.press(down && return1_btn.contains(pixel_x, pixel_y));
if (return1_btn.justReleased())
return1_btn.drawButton();
if (return1_btn.justPressed()) {
return1_btn.drawButton(true);
tft.fillRect(40, 8, 160, 4, BLACK);
Serial.println("RETURN TO KEYPAD");
delay(100);
callScrn = false;
keyScrn = true;
drawKeypad();
}
}