Instantly share code, notes, and snippets.
Created
March 9, 2024 17:33
-
Save Ajak58a/c4a3e709b71310ed705e48b7ade316d4 to your computer and use it in GitHub Desktop.
Digital menu using the MIT Inventor App
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Adafruit_GFX.h> | |
#include <MCUFRIEND_kbv.h> | |
#include "TouchScreen.h" | |
#define BLACK 0x0000 | |
#define BLUE 0x001F | |
#define RED 0xF800 | |
#define GREEN 0x07E0 | |
#define CYAN 0x07FF | |
#define MAGENTA 0xF81F | |
#define YELLOW 0xFFE0 | |
#define WHITE 0xFFFF | |
MCUFRIEND_kbv tft; | |
#define MINPRESSURE 10 | |
#define MAXPRESSURE 1000 | |
const int XP=6,XM=A2,YP=A1,YM=7; //320x480 ID=0x9486 | |
const int TS_LEFT=931,TS_RT=168,TS_TOP=452,TS_BOT=191; | |
#define TS_MINX 125 | |
#define TS_MINY 85 | |
#define TS_MAXX 965 | |
#define TS_MAXY 905 | |
TouchScreen ts(XP, YP, XM, YM, 300); //re-initialised after diagnose | |
TSPoint tp; //global point | |
void setup(void) { | |
tft.reset(); | |
tft.begin(tft.readID()); | |
tft.setRotation(2); | |
Serial.begin(9600); | |
Serial1.begin(9600); | |
Serial.println(); | |
Serial.print("reading id..."); | |
delay(500); | |
Serial.println(tft.readID(), HEX); | |
tft.fillScreen(BLACK); | |
Menu(); | |
} | |
void Menu() | |
{ | |
tft.fillScreen(BLACK); | |
tft.drawRoundRect(0, 0, 320, 480, 8, WHITE); //Page border | |
tft.setCursor(140, 5); | |
tft.setTextSize(2); | |
tft.setTextColor(CYAN); | |
tft.print("Menu"); | |
tft.setCursor(5, 30); | |
tft.drawRoundRect(5, 30, 300, 30, 8, WHITE); //Vote | |
tft.fillRoundRect(5, 30, 300, 30, 8, YELLOW); | |
tft.setTextColor(BLACK); | |
tft.setCursor(10, 38); | |
tft.print("OTC Pizza"); | |
tft.setCursor(5, 65); | |
tft.drawRoundRect(5, 65, 300, 30, 8, WHITE); //Vote | |
tft.fillRoundRect(5, 65, 300, 30, 8, YELLOW); | |
tft.setTextColor(BLACK); | |
tft.setCursor(10, 73); | |
tft.print("Mix Veg Pizza"); | |
tft.setCursor(5, 100); | |
tft.drawRoundRect(5, 100, 300, 30, 8, WHITE); //Vote | |
tft.fillRoundRect(5, 100, 300, 30, 8, YELLOW); | |
tft.setTextColor(BLACK); | |
tft.setCursor(10, 108); | |
tft.print("American Corn Pizza"); | |
tft.setCursor(5, 135); | |
tft.drawRoundRect(5, 135, 300, 30, 8, WHITE); //Vote | |
tft.fillRoundRect(5, 135, 300, 30, 8, YELLOW); | |
tft.setTextColor(BLACK); | |
tft.setCursor(10, 143); | |
tft.print("Margherita Pizza"); | |
tft.setCursor(5, 170); | |
tft.drawRoundRect(5, 170, 300, 30, 8, WHITE); //Vote | |
tft.fillRoundRect(5, 170, 300, 30, 8, YELLOW); | |
tft.setTextColor(BLACK); | |
tft.setCursor(10, 178); | |
tft.print("Paneer Cheese Pizza"); | |
tft.setCursor(5, 205); | |
tft.drawRoundRect(5, 205, 300, 30, 8, WHITE); //Vote | |
tft.fillRoundRect(5, 205, 300, 30, 8, YELLOW); | |
tft.setTextColor(BLACK); | |
tft.setCursor(10, 213); | |
tft.print("COC Pizza"); | |
tft.setCursor(5, 240); | |
tft.drawRoundRect(5, 240, 300, 30, 8, WHITE); //Vote | |
tft.fillRoundRect(5, 240, 300, 30, 8, YELLOW); | |
tft.setTextColor(BLACK); | |
tft.setCursor(10, 248); | |
tft.print("Red Pasta"); | |
tft.setCursor(5, 275); | |
tft.drawRoundRect(5, 275, 300, 30, 8, WHITE); //Vote | |
tft.fillRoundRect(5, 275, 300, 30, 8, YELLOW); | |
tft.setTextColor(BLACK); | |
tft.setCursor(10, 283); | |
tft.print("White Pasta"); | |
tft.setCursor(5, 310); | |
tft.drawRoundRect(5, 310, 300, 30, 8, WHITE); //Vote | |
tft.fillRoundRect(5, 310, 300, 30, 8, YELLOW); | |
tft.setTextColor(BLACK); | |
tft.setCursor(10, 318); | |
tft.print("Honey Chilli Potato"); | |
tft.setCursor(5, 345); | |
tft.drawRoundRect(5, 345, 300, 30, 8, WHITE); //Vote | |
tft.fillRoundRect(5, 345, 300, 30, 8, YELLOW); | |
tft.setTextColor(BLACK); | |
tft.setCursor(10, 353); | |
tft.print("Cold Coffee"); | |
tft.drawRoundRect(5, 380, 100, 90, 8, RED); //Vote | |
tft.fillRoundRect(5, 380, 100, 90, 8, RED); | |
tft.setTextColor(WHITE); | |
tft.setCursor(10, 406); | |
tft.print("Call"); | |
tft.setCursor(10, 436); | |
tft.print("Waiter"); | |
tft.drawRoundRect(110, 380, 100, 90, 8, RED); //Vote | |
tft.fillRoundRect(110, 380, 100, 90, 8, RED); | |
tft.setTextColor(WHITE); | |
tft.setCursor(140, 416); | |
tft.print("Bill"); | |
tft.drawRoundRect(215, 380, 100, 90, 8, RED); //Vote | |
tft.fillRoundRect(215, 380, 100, 90, 8, RED); | |
tft.setTextColor(WHITE); | |
tft.setCursor(245, 416); | |
tft.print("Water"); | |
} | |
void loop(){ | |
digitalWrite(13, HIGH); | |
digitalWrite(13, LOW); | |
TSPoint p = ts.getPoint(); | |
// if sharing pins, you'll need to fix the directions of the touchscreen pins | |
//pinMode(XP, OUTPUT); | |
//pinMode(YM, OUTPUT); | |
pinMode(XM, OUTPUT); | |
pinMode(YP, OUTPUT); | |
if (p.z > ts.pressureThreshhold) | |
{ | |
p.x = map(p.x, TS_MAXX, TS_MINX, 0, 320); | |
p.y = map(p.y, TS_MAXY, TS_MINY, 0, 240); | |
// Serial.print("X:"); // I used this to get the accurate touch points for X and Y axis | |
// Serial.print(p.x); | |
// Serial.print(" "); | |
// Serial.print("Y:"); | |
// Serial.println(p.y); | |
if (p.x > 20 && p.x < 305 && p.y > 193 && p.y < 205 && p.z > MINPRESSURE && p.z < MAXPRESSURE) | |
{ | |
Serial1.println("OTC Pizza Ordered"); | |
delay(1000); | |
} | |
if (p.x > 20 && p.x < 305 && p.y > 175 && p.y < 187 && p.z > MINPRESSURE && p.z < MAXPRESSURE) | |
{ | |
Serial1.println("Mix Veg Pizza Ordered"); | |
delay(1000); | |
} | |
if (p.x > 20 && p.x < 305 && p.y > 160 && p.y < 170 && p.z > MINPRESSURE && p.z < MAXPRESSURE) | |
{ | |
Serial1.println("American Corn Pizza Ordered"); | |
delay(1000); | |
} | |
if (p.x > 20 && p.x < 305 && p.y > 142 && p.y < 153 && p.z > MINPRESSURE && p.z < MAXPRESSURE) | |
{ | |
Serial1.println("Margherita Pizza Ordered"); | |
delay(1000); | |
} | |
if (p.x > 20 && p.x < 305 && p.y > 122 && p.y < 135 && p.z > MINPRESSURE && p.z < MAXPRESSURE) | |
{ | |
Serial1.println("Paneer Cheese Pizza Ordered"); | |
delay(1000); | |
} | |
if (p.x > 20 && p.x < 305 && p.y > 105 && p.y < 117 && p.z > MINPRESSURE && p.z < MAXPRESSURE) | |
{ | |
Serial1.println("COC Pizza Ordered"); | |
delay(1000); | |
} | |
if (p.x > 20 && p.x < 305 && p.y > 88 && p.y < 100 && p.z > MINPRESSURE && p.z < MAXPRESSURE) | |
{ | |
Serial1.println("Red Pasta Ordered"); | |
delay(1000); | |
} | |
if (p.x > 20 && p.x < 305 && p.y > 70 && p.y < 82 && p.z > MINPRESSURE && p.z < MAXPRESSURE) | |
{ | |
Serial1.println("White Pasta Ordered"); | |
delay(1000); | |
} | |
if (p.x > 20 && p.x < 310 && p.y > 50 && p.y < 65 && p.z > MINPRESSURE && p.z < MAXPRESSURE) | |
{ | |
Serial1.println("Honey Chilli Ordered"); | |
delay(1000); | |
} | |
if (p.x > 20 && p.x < 310 && p.y > 35 && p.y < 45 && p.z > MINPRESSURE && p.z < MAXPRESSURE) | |
{ | |
Serial1.println("Cold Coffee Ordered"); | |
delay(1000); | |
} | |
if (p.x > 220 && p.x < 300 && p.y > -5 && p.y < 30 && p.z > MINPRESSURE && p.z < MAXPRESSURE) | |
{ | |
Serial1.println("Call Waiter"); | |
delay(1000); | |
} | |
if (p.x > 115 && p.x < 210 && p.y > -5 && p.y < 30 && p.z > MINPRESSURE && p.z < MAXPRESSURE) | |
{ | |
Serial1.println("Bill"); | |
delay(1000); | |
} | |
if (p.x > 20 && p.x < 100 && p.y > -5 && p.y < 30 && p.z > MINPRESSURE && p.z < MAXPRESSURE) | |
{ | |
Serial1.println("Water"); | |
delay(1000); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment