Professional Documents
Culture Documents
#define BUZZER_PORT 49
bool showingKeypad = false; // Add this line at the top of your sketch
MCUFRIEND_kbv tft;
tft.setCursor(textX, textY);
tft.println(label);
delay(100); // Delay for button press effect
}
void updateItemCountDisplay() {
int startYNumber = 20; // Adjust as needed
tft.fillRect(startX, startYNumber, buttonWidth, buttonHeight, BLACK);
tft.drawRect(startX, startYNumber, buttonWidth, buttonHeight, WHITE);
tft.setCursor(startX + (buttonWidth - 4 * 6) / 2, startYNumber + (buttonHeight
- 16) / 2);
tft.setTextSize(2);
tft.setTextColor(WHITE);
char numStr[5];
sprintf(numStr, "%04d", itemCount);
tft.println(numStr);
}
void drawKeypad() {
tft.fillScreen(BLACK);
tft.setTextColor(WHITE);
tft.setTextSize(2);
const char *keys[12] = {"1", "2", "3", "4", "5", "6", "7", "8", "9", "*", "0",
"#"};
void enterEditMode() {
itemCount = 0; // Reset the number to zero
showingKeypad = true;
displayNumericKeypad();
}
void setup() {
uint16_t ID = tft.readID();
tft.begin(ID);
tft.setRotation(2); // Adjust as needed
void displayMainMenu() {
tft.fillScreen(BLACK);
tft.setTextColor(WHITE);
tft.setTextSize(2);
// Start Button
tft.drawRect(startX, startYStart, buttonWidth, buttonHeight, WHITE);
tft.setCursor(startX + (buttonWidth - 6 * 5) / 2, startYStart + (buttonHeight -
16) / 2);
tft.println("Start");
// Stop Button
int startYStop = startYStart + buttonHeight + gap;
tft.drawRect(startX, startYStop, buttonWidth, buttonHeight, WHITE);
tft.setCursor(startX + (buttonWidth - 6 * 4) / 2, startYStop + (buttonHeight -
16) / 2);
tft.println("Stop");
void displayManualMode() {
tft.fillScreen(BLACK);
tft.setTextColor(WHITE);
tft.setTextSize(2);
// 0000 Indicator
int startYIndicator = 20;
tft.drawRect(startX, startYIndicator, buttonWidth, buttonHeight, WHITE);
updateItemCountDisplay(); // Update the 0000 display
// Edit Button
int startYEdit = startYIndicator + buttonHeight + 10;
tft.drawRect(startX, startYEdit, buttonWidth, buttonHeight, WHITE);
tft.setCursor(startX + (buttonWidth - 6 * 4) / 2, startYEdit + (buttonHeight -
16) / 2);
tft.println("Edit");
// Start Button
int startYStart = startYEdit + buttonHeight + 10;
tft.drawRect(startX, startYStart, buttonWidth, buttonHeight, WHITE);
tft.setCursor(startX + (buttonWidth - 6 * 5) / 2, startYStart + (buttonHeight -
16) / 2);
tft.println("Start");
// Pause/Continue Button
int startYPause = startYStart + buttonHeight + 10;
tft.drawRect(startX, startYPause, buttonWidth, buttonHeight, WHITE);
tft.setCursor(startX + (buttonWidth - 6 * (isPaused ? 8 : 5)) / 2, startYPause
+ (buttonHeight - 16) / 2);
tft.println(isPaused ? "Continue" : "Pause");
// Stop Button
int startYStop = startYPause + buttonHeight + 10;
tft.drawRect(startX, startYStop, buttonWidth, buttonHeight, WHITE);
tft.setCursor(startX + (buttonWidth - 6 * 4) / 2, startYStop + (buttonHeight -
16) / 2);
tft.println("Stop");
void displayNumericKeypad() {
tft.fillScreen(BLACK); // Clear the screen
tft.setTextColor(WHITE);
tft.setTextSize(2);
const char *keys[12] = {"1", "2", "3", "4", "5", "6", "7", "8", "9", "*", "0",
"#"};
void loop() {
digitalWrite(YP, HIGH); // disable Pull-up
digitalWrite(XM, HIGH); // disable Pull-up
TSPoint p = ts.getPoint();
digitalWrite(YP, LOW); // enable Pull-down
digitalWrite(XM, LOW); // enable Pull-down
pinMode(XM, OUTPUT);
pinMode(YP, OUTPUT);
}
else if (inAutoMode) {
// Start Button
int startYStart = screen_height / 6;
if (p.x > startX && p.x < startX + buttonWidth && p.y > startYStart &&
p.y < startYStart + buttonHeight) {
updateButton(startX, startYStart, "Start", WHITE, BLACK, buttonWidth,
buttonHeight);
delay(100);
displayAutoMode();
}
// Stop Button
int startYStop = startYStart + buttonHeight + 20;
if (p.x > startX && p.x < startX + buttonWidth && p.y > startYStop &&
p.y < startYStop + buttonHeight) {
updateButton(startX, startYStop, "Stop", WHITE, BLACK, buttonWidth,
buttonHeight);
delay(100);
displayAutoMode();
}
// Return to Main Menu Button
int startYReturn = startYStop + buttonHeight + 20;
if (p.x > startX && p.x < startX + buttonWidth && p.y > startYReturn &&
p.y < startYReturn + buttonHeight) {
updateButton(startX, startYReturn, "Back", WHITE, BLACK, buttonWidth,
buttonHeight);
displayMainMenu();
inAutoMode = false;
}
}
else if (inManualMode) {
if (showingKeypad) {
// Numeric Keypad and OK button detection
for (int row = 0; row < 4; ++row) {
for (int col = 0; col < 3; ++col) {
int x = keypadStartX + col * (keyWidth + keyPadding);
int y = keypadStartY + row * (keyHeight + keyPadding);
if (p.x >= x && p.x < x + keyWidth && p.y >= y && p.y < y + keyHeight) {
int numKey = row * 3 + col + 1;
if (numKey <= 9) { // Keys 1-9
itemCount = (itemCount % 1000) * 10 + numKey; // Shift left and add
new digit
} else if (numKey == 10) { // Key 0
itemCount = (itemCount % 1000) * 10;
} else if (numKey == 11) { // Clear or other function
itemCount = 0;
}
updateItemCountDisplay();
delay(100); // Debounce delay
}
}
}
// OK Button
int startYOK = keypadStartY + 4 * (keyHeight + keyPadding);
if (p.x > startX && p.x < startX + buttonWidth && p.y > startYOK &&
p.y < startYOK + buttonHeight) {
updateButton(startX, startYOK, "OK", WHITE, BLACK, buttonWidth,
buttonHeight);
delay(100); // Delay for button press effect
showingKeypad = false;
displayManualMode();
}
} else {
// Edit Button
int startYEdit = 20 + buttonHeight + 10;
if (p.x > startX && p.x < startX + buttonWidth && p.y > startYEdit && p.y <
startYEdit + buttonHeight) {
updateButton(startX, startYEdit, "Edit", WHITE, BLACK, buttonWidth,
buttonHeight);
delay(100); // Delay for button press effect
enterEditMode(); // Enter edit mode and reset number
}
// Start Button
int startYStart = startYEdit + buttonHeight + 10;
if (p.x > startX && p.x < startX + buttonWidth && p.y > startYStart
&& p.y < startYStart + buttonHeight) {
updateButton(startX, startYStart, "Start", WHITE, BLACK,
buttonWidth, buttonHeight);
delay(100); // Delay for button press effect
displayManualMode(); // Redraw the screen to update the button
label
}
// Pause/Continue Button
int startYPause = startYStart + buttonHeight + 10;
if (p.x > startX && p.x < startX + buttonWidth && p.y > startYPause
&& p.y < startYPause + buttonHeight) {
isPaused = !isPaused; // Toggle the pause state
updateButton(startX, startYPause, isPaused ? "Continue" :
"Pause", WHITE, BLACK, buttonWidth, buttonHeight);
delay(100); // Delay for button press effect
displayManualMode(); // Redraw the screen to update the button
label
}
// Stop Button
int startYStop = startYPause + buttonHeight + 10;
if (p.x > startX && p.x < startX + buttonWidth && p.y > startYStop
&& p.y < startYStop + buttonHeight) {
updateButton(startX, startYStop, "Stop", WHITE, BLACK,
buttonWidth, buttonHeight);
delay(100); // Delay for button press effect
displayManualMode(); // Redraw the screen to update the button
label
}