Professional Documents
Culture Documents
// Triangle properties
const int centerX = 120; // Center of rotation X
const int centerY = 160; // Center of rotation Y
const int radius = 120; // Radius of rotation
const float rotationSpeed = 1; // Rotation speed in degrees per frame
#define LS1 35
#define LS2 37
#define LDR1 41
#define LASER 43
#define MOTOR_IN1 51
#define MOTOR_IN2 49
#define MOTOR_IN3 47
#define MOTOR_IN4 45
#define BUZZER 31
#define IR_SENSOR 33
#define ORANGE ((31 << 11) | (15 << 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 DARK_BLUE 0x00008B // Dark blue color
#define DARK_RED 0x8B0000 // Dark red color
#define PRIMARY_COLOR 0x4A11
#define PRIMARY_LIGHT_COLOR 0x7A17
#define PRIMARY_DARK_COLOR 0x4016
#define PRIMARY_TEXT_COLOR 0x7FFF
bool buttonPressed = false; // At the beginning of your code, declare this variable
MCUFRIEND_kbv tft;
void startMotor1() {
digitalWrite(MOTOR_IN1, HIGH);
digitalWrite(MOTOR_IN2, LOW);
motor1Running = true;
}
void stopMotor1() {
digitalWrite(MOTOR_IN1, LOW);
digitalWrite(MOTOR_IN2, LOW);
motor1Running = false;
}
void rotateMotor2Clockwise() {
digitalWrite(MOTOR_IN3, HIGH);
digitalWrite(MOTOR_IN4, LOW);
delay(3000); // Run motor for 3 seconds
digitalWrite(MOTOR_IN3, LOW);
digitalWrite(MOTOR_IN4, LOW);
}
tft.setCursor(textX, textY);
tft.println(label);
delay(500); // Delay for button press effect
}
void drawKey(int x, int y, const char* label, uint16_t bgColor, uint16_t textColor)
{
tft.fillRect(x, y, keyWidth, keyHeight, bgColor);
tft.setTextColor(textColor);
tft.setTextSize(2); // Adjust text size as needed
tft.setCursor(x + (keyWidth - strlen(label) * 6) / 2, y + (keyHeight - 8) / 2);
// Adjust for text size
tft.println(label);
}
void updateItemCountDisplay() {
// Position and size settings
int startYNumber = 20; // Y position of the number
int itemTextX = startX - 50; // X position of the "Items" text, adjust as
needed
int itemTextY = startYNumber + 10; // Y position of the "Items" text, align
with number
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",
"#"};
float readTemperature() {
int analogValue = analogRead(THERMISTOR_PIN); // Read the analog value from
thermistor
float resistance = (1023.0 / analogValue - 1.0) * THERMISTOR_RESISTANCE;
void enterEditMode() {
itemCount = 0; // Reset the number to zero
showingKeypad = true;
displayNumericKeypad();
}
void updateAutoModeItemCountDisplay() {
tft.setCursor(10, 20); // Example coordinates, adjust as necessary
tft.setTextColor(WHITE, BLACK); // Set text color and background color
tft.setTextSize(2); // Set text size
tft.print("Items: ");
tft.print(autoModeItemCount);
}
void drawResetButton() {
tft.fillRect(resetButtonX, resetButtonY, resetButtonWidth, resetButtonHeight,
BLUE); // Choose a color
tft.drawRect(resetButtonX, resetButtonY, resetButtonWidth, resetButtonHeight,
WHITE); // Border
tft.setCursor(resetButtonX + 10, resetButtonY + 10); // Adjust text position as
needed
tft.setTextColor(WHITE);
tft.setTextSize(2);
tft.print("Reset");
}
void setup() {
uint16_t ID = tft.readID();
tft.begin(ID);
tft.setRotation(2); // Adjust as needed
delay(2000);
drawBarGraphFrame();
void drawBarGraphFrame() {
const int barGraphX = 10;
const int barGraphY = 380;
const int barGraphWidth = 220;
const int barGraphHeight = 10;
void displayMainMenu() {
tft.fillScreen(BLACK);
tft.setTextColor(WHITE);
tft.setTextSize(2);
tft.setTextSize(2);
tft.setTextColor(YELLOW); // Set the text color (choose a color that contrasts well
with the background)
tft.setCursor(12, 10); // Position the text cursor
tft.println("--SUPER ITEMISER--");
tft.setCursor(25, 40); // Position the text cursor
tft.setTextSize(1);
tft.println("Designed by");
tft.setTextColor(MAGENTA);
tft.setCursor(97, 40); // Position the text cursor
tft.println("S0t0S");
tft.setTextColor(WHITE); // Set the text color (choose a color that contrasts well
with the background)
tft.setCursor(131, 40); // Position the text cursor
tft.println("for");
tft.setTextColor(GREEN); // Set the text color (choose a color that contrasts well
with the background)
tft.setCursor(153, 40); // Position the text cursor
tft.println("CBDOILSHOP");
tft.setTextSize(2);
tft.setTextColor(WHITE); // Set the text color (choose a color that contrasts well
with the background)
tft.setCursor(32, 79); // Position the text cursor
tft.println("CHOOSE MODE");
startYAuto = 120;
tft.setTextSize(3);
// Auto Mode Button (using button2 dimensions)
tft.fillRect(startX, startYAuto, button2Width, button2Height, backgroundColor); //
Fill the button with background color
tft.drawRect(startX, startYAuto, button2Width, button2Height, WHITE); // Draw the
button border
tft.setTextColor(BLACK); // Set the text color (choose a color that contrasts well
with the background)
tft.setCursor(startX + (button2Width - 8 * 9) / 2, startYAuto + (button2Height -
20) / 2); // Position the text cursor
tft.println("AUTO"); // Print the button label
void displayAutoMode() {
tft.fillScreen(BLACK);
tft.setTextColor(WHITE);
tft.setTextSize(2);
// Start Button
tft.drawRect(startX, startYStart, buttonWidth, buttonHeight, WHITE);
drawPlaySymbol(startX + 12, startYStart +13, GREEN); // Adjust position as
needed
tft.setCursor(startX + (buttonWidth - 6 * 5) / 2, startYStart + (buttonHeight -
16) / 2);
tft.println("Start");
// Stop Button
tft.drawRect(startX, startYStop, buttonWidth, buttonHeight, WHITE);
drawStopSymbol(startX + 12, startYStop + 12, RED); // Adjust position as needed
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, manualButtonWidth, manualButtonHeight,
WHITE);
updateItemCountDisplay(); // Update the 0000 display
// Edit Button
int startYEdit = startYIndicator + manualButtonHeight + 10;
tft.drawRect(startX, startYEdit, manualButtonWidth, manualButtonHeight, WHITE);
drawCircleSymbol(startX + 18, startYEdit + 13, CYAN); // Adjust position as
needed
tft.setCursor(startX + (manualButtonWidth - 6 * 4) / 2, startYEdit +
(manualButtonHeight - 16) / 2);
tft.setTextSize(2);
tft.println("Edit");
// Start Button
int startYStart = startYEdit + manualButtonHeight + 10;
tft.drawRect(startX, startYStart, manualButtonWidth, manualButtonHeight,
WHITE);
drawPlaySymbol(startX + 12, startYStart + 13, GREEN); // Adjust position as
needed
tft.setCursor(startX + (manualButtonWidth - 6 * 5) / 2, startYStart +
(manualButtonHeight - 16) / 2);
tft.println("Start");
// Pause/Continue Button
int startYPause = startYStart + manualButtonHeight + 10;
if (isPaused) {
drawBlinkingArrowSymbol(startX + 12, startYPause + 2, YELLOW); // For
"Continue" - Adjust position as needed
tft.drawRect(startX, startYPause, manualButtonWidth,
manualButtonHeight, WHITE);
tft.setCursor(startX + (manualButtonWidth - 6 * (isPaused ? 8 : 5)) / 2,
startYPause + (manualButtonHeight - 16) / 2);
tft.println("Continue");
} else {
drawPauseSymbol(startX + 12, startYPause + 2, BLUE); // For "Pause" -
Adjust position as needed
tft.drawRect(startX, startYPause, manualButtonWidth, manualButtonHeight,
WHITE);
tft.setCursor(startX + (manualButtonWidth - 6 * (isPaused ? 8 : 5)) / 2,
startYPause + (manualButtonHeight - 16) / 2);
tft.println("Pause");
}
// Stop Button
int startYStop = startYPause + manualButtonHeight + 10;
tft.drawRect(startX, startYStop, manualButtonWidth, manualButtonHeight, WHITE);
drawStopSymbol(startX + 12, startYStop + 13, RED); // Adjust position as needed
tft.setCursor(startX + (manualButtonWidth - 6 * 4) / 2, startYStop +
(manualButtonHeight - 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 runMotor2For3Seconds() {
// Assuming MOTOR_IN3 and MOTOR_IN4 control the second motor
digitalWrite(MOTOR_IN3, HIGH); // Start motor2 (adjust based on your setup)
digitalWrite(MOTOR_IN4, LOW);
delay(3000); // Run for 3 seconds
digitalWrite(MOTOR_IN3, LOW); // Stop motor2
digitalWrite(MOTOR_IN4, LOW);
}
void circle() {
startMotor1(); // Start motor1
// Start motor2
digitalWrite(MOTOR_IN3, HIGH);
digitalWrite(MOTOR_IN4, LOW);
// Stop motor2
digitalWrite(MOTOR_IN3, LOW);
digitalWrite(MOTOR_IN4, LOW);
}
// Global variable to keep track of the previous bar length
int previousBarLength = 0;
void drawRotatingTriangles() {
const int centerX = tft.width() / 2;
const int centerY = tft.height() / 2;
const int radius = 50; // Adjust as needed
const int numSteps = 36; // Number of steps in rotation (10 degrees per step)
tft.setTextColor(MAGENTA);
tft.setTextSize(2);
tft.setCursor(centerX - 50, centerY + radius + 30); // Position the cursor
above the triangles
tft.print("Welcome!");
void drawTriangle(int centerX, int centerY, int radius, float angle, uint16_t
color) {
// Calculate the vertices of the triangle
int x1 = centerX + radius * cos(angle);
int y1 = centerY + radius * sin(angle);
void loop() {
float temperature;
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);
// Calculate resistance
float resistance = SERIES_RESISTOR * ((1023.0 / thermistorReading) - 1);
// Calculate temperature
temperature = (BETA_CONSTANT / (log(resistance / THERMISTOR_NOMINAL_RESISTANCE)
+ BETA_CONSTANT / (THERMISTOR_NOMINAL_TEMPERATURE + 273.15))) - 273.15;
}
} else if (inAutoMode) {
// Start Button
int startYStart = screen_height / 3;
if (p.x > startX && p.x < startX + buttonWidth && p.y >
startYStart && p.y < startYStart + buttonHeight) {
updateButton(startX, startYStart, "Start", WHITE, BLACK,
buttonWidth, buttonHeight);
circle(); // Perform one circle
digitalWrite(LASER, HIGH); // Turn on the laser
delay(500);
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);
stopRequested = true;
pauseRequested = false; // Reset pause state if stop is
requested
digitalWrite(LASER, LOW); // Turn on the laser
delay(500);
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 buttons
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", DARK_RED, WHITE,
buttonWidth, buttonHeight);
delay(500); // Delay for button press effect
showingKeypad = false;
displayManualMode();
}
} else {
// Edit Button
int startYEdit = 20 + manualButtonHeight + 10;
if (p.x > startX && p.x < startX + manualButtonWidth && p.y >
startYEdit && p.y < startYEdit + manualButtonHeight) {
updateButton(startX, startYEdit, "Edit", WHITE, BLACK,
manualButtonWidth, manualButtonHeight);
delay(500); // Delay for button press effect
enterEditMode(); // Enter edit mode and reset number
}
// Start Button
int startYStart = startYEdit + manualButtonHeight + 10;
if (p.x > startX && p.x < startX + manualButtonWidth && p.y >
startYStart && p.y < startYStart + manualButtonHeight) {
updateButton(startX, startYStart, "Start", WHITE, BLACK, manualButtonWidth,
manualButtonHeight);
circle(); // Perform one circle
digitalWrite(LASER, HIGH); // Turn off the laser
manualModeStarted = true; // Set the flag here
delay(500);
displayManualMode();
}
// Stop Button
int startYStop = startYPause + manualButtonHeight + 10;
if (p.x > startX && p.x < startX + manualButtonWidth && p.y >
startYStop && p.y < startYStop + manualButtonHeight) {
updateButton(startX, startYStop, "Stop", WHITE, BLACK,
manualButtonWidth, manualButtonHeight);
stopMotor1();
digitalWrite(LASER, LOW); // Turn off the laser
delay(500); // Delay for button press effect
displayManualMode();
}
}
// Handle motor and sensor logic
if (inAutoMode && !isPaused) {
// Auto Mode specific motor and sensor logic
// For example, checking LDR sensor, starting and stopping motors, etc.
}