#include <Adafruit_FT6206.h>
#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>
#include <SPI.h>
#include <SD.h>
#include <WiFi.h>
// ========== PIN DEFINITIONS ==========
// TFT Display
#define TFT_CS 15
#define TFT_DC 2
#define TFT_RST 4
// SD Card
#define SD_CS 5
// ======== OBJECTS ========
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST);
Adafruit_FT6206 ctp = Adafruit_FT6206();
// ========== SYMPTOM DATABASE ==========
String symptoms[] = {
"Engine won't start",
"Battery drains fast",
"Check engine light on",
"Overheating",
"Weird noise when driving",
"Car shakes when idle",
"Brake pedal feels soft",
"Smoke from exhaust",
"AC not working",
"Car pulls to one side",
"Transmission slipping",
"Fuel usage too high"
};
String diagnoses[] = {
"Battery, starter, or fuel pump issue",
"Alternator or parasitic drain",
"Scan with OBD2 scanner",
"Coolant leak or fan failure",
"Suspension or loose parts",
"Engine misfire or bad mounts",
"Air in brakes or worn pads",
"Burning oil or fuel, engine wear",
"AC refrigerant or compressor issue",
"Alignment or tire pressure",
"Low transmission fluid",
"Dirty filter or spark plugs"
};
const int symptomCount = sizeof(symptoms) / sizeof(symptoms[0]);
int symptomBoxHeight = 20;
// ========== WIFI SETTINGS ==========
const char* ssid = "Wokwi-GUEST";
const char* password = "";
// ========== FUNCTION DEFINITIONS ==========
String getNearestWorkshop() {
// Placeholder ā Replace with real API later
return "Nearby Workshop:\nMaju Auto Service\n2.5 km away\nš 012-3456789";
}
void saveToSD(String symptom, String diagnosis) {
File logFile = SD.open("/diagnosis_log.txt", FILE_APPEND);
if (logFile) {
logFile.println("Symptom: " + symptom);
logFile.println("Diagnosis: " + diagnosis);
logFile.println("---");
logFile.close();
Serial.println("Saved to SD.");
} else {
Serial.println("Failed to open log file.");
}
}
void showSymptoms() {
tft.fillScreen(ILI9341_BLACK);
tft.setTextSize(1);
tft.setTextColor(ILI9341_WHITE);
for (int i = 0; i < symptomCount; i++) {
tft.fillRect(0, i * symptomBoxHeight, 320, symptomBoxHeight, ILI9341_DARKGREY);
tft.setCursor(5, i * symptomBoxHeight + 5);
tft.println(symptoms[i]);
}
}
void showDiagnosis(int index) {
tft.fillScreen(ILI9341_BLACK);
tft.setTextColor(ILI9341_GREEN);
tft.setTextSize(2);
tft.setCursor(10, 10);
tft.println("Diagnosis:");
tft.setTextSize(1);
tft.setTextColor(ILI9341_WHITE);
tft.setCursor(10, 50);
tft.println(diagnoses[index]);
tft.setTextColor(ILI9341_YELLOW);
tft.setCursor(10, 100);
tft.println(getNearestWorkshop());
}
// ========== SETUP ==========
void setup() {
Serial.begin(115200);
tft.begin();
tft.setRotation(1);
if (!ctp.begin()) {
Serial.println("Touchscreen not found");
while (1);
}
// Connect to WiFi
WiFi.begin(ssid, password);
tft.setTextSize(1);
tft.setTextColor(ILI9341_WHITE);
tft.setCursor(10, 200);
tft.print("Connecting WiFi");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
tft.print(".");
}
tft.setCursor(10, 210);
tft.println("\nWiFi connected");
Serial.println("IP: " + WiFi.localIP().toString());
// SD card init
if (!SD.begin(SD_CS)) {
Serial.println("SD init failed.");
} else {
Serial.println("SD ready.");
}
showSymptoms();
}
// ========== MAIN LOOP ==========
void loop() {
if (ctp.touched()) {
TS_Point p = ctp.getPoint();
// Convert raw touch coordinates to screen coordinates
int x = map(p.y, 0, 240, 0, 320); // depends on screen orientation
int y = map(p.x, 0, 320, 0, 240);
int selected = y / symptomBoxHeight;
if (selected >= 0 && selected < symptomCount) {
showDiagnosis(selected);
saveToSD(symptoms[selected], diagnoses[selected]);
delay(3000);
showSymptoms();
}
}
}
Loading
ili9341-cap-touch
ili9341-cap-touch