#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>
// Define the TFT display pins
#define TFT_CS 10
#define TFT_RST 8
#define TFT_DC 9
// Create the TFT display object
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST);
// Define button pins for the number pad (you'll need 12 buttons)
const int buttonPins[] = {2, 3, 4, 5, 6, 7, 11, 12, A0, A1, A2, A3}; // For 0-9 + call/end
String dialedNumber = ""; // Store the dialed number
void setup() {
// Start serial communication for debugging
Serial.begin(9600);
// Initialize TFT screen
tft.begin();
// Set screen rotation (adjust according to your physical setup)
tft.setRotation(3); // Try 0, 1, 2, or 3 depending on how you want the screen to appear
// Set background color to white
tft.fillScreen(ILI9341_WHITE);
// Display the dialer UI
drawDialer();
// Initialize button pins as input
for (int i = 0; i < 12; i++) {
pinMode(buttonPins[i], INPUT_PULLUP);
}
}
void loop() {
// Check each button for a press
for (int i = 0; i < 12; i++) {
if (digitalRead(buttonPins[i]) == LOW) {
handleButtonPress(i);
delay(300); // debounce delay
}
}
}
void drawDialer() {
// Display the dialer screen
tft.setTextColor(ILI9341_BLACK);
tft.setTextSize(3);
tft.setCursor(10, 10);
tft.print("Dialer: ");
tft.setCursor(10, 40);
tft.print(dialedNumber); // Show dialed number
// Draw number pad (simple layout)
int x = 10, y = 100;
for (int i = 1; i <= 9; i++) {
if (i % 3 == 0) { x = 10; y += 50; } // Move to next row after every 3 buttons
drawButton(x, y, i);
x += 60;
}
drawButton(10, y + 50, 0); // Add "0" at the bottom
drawButton(70, y + 50, 10); // Add "Call"
drawButton(130, y + 50, 11); // Add "End"
}
void drawButton(int x, int y, int num) {
// Draw a button on the screen
tft.fillRect(x, y, 50, 50, ILI9341_LIGHTGREY); // Corrected color name
tft.drawRect(x, y, 50, 50, ILI9341_BLACK);
tft.setCursor(x + 15, y + 15);
if (num == 10) {
tft.setTextSize(2);
tft.print("Call");
} else if (num == 11) {
tft.setTextSize(2);
tft.print("End");
} else {
tft.setTextSize(3);
tft.print(num);
}
}
void handleButtonPress(int buttonIndex) {
// Handle number or call/end button press
if (buttonIndex >= 0 && buttonIndex <= 9) {
dialedNumber += String(buttonIndex);
} else if (buttonIndex == 10) {
// Simulate a call (just display "Calling")
tft.fillRect(10, 200, 240, 40, ILI9341_WHITE);
tft.setCursor(10, 200);
tft.print("Calling " + dialedNumber + "...");
} else if (buttonIndex == 11) {
// Simulate end of call (reset the dialer)
dialedNumber = "";
tft.fillRect(10, 200, 240, 40, ILI9341_WHITE);
drawDialer(); // Redraw the dialer screen
}
}