

This circuit is designed to interface an Arduino Mega 2560 with an ILI9341 TFT display and multiple pushbuttons. The primary function of this circuit appears to be a voting system, where the Arduino Mega 2560 collects inputs from the pushbuttons and displays the voting results on the TFT display. The pushbuttons are likely used for voters to select their choices, and the system is capable of displaying the vote counts in real-time.
3V3 connected to ILI9341 TFT Display LED5V connected to ILI9341 TFT Display VCCGND connected to ILI9341 TFT Display GND and all Pushbutton Pin 1 (in)D7 PWM connected to Pushbutton Pin 2D8 PWM connected to ILI9341 TFT Display RESETD9 PWM connected to ILI9341 TFT Display DC/RSD10 PWM connected to ILI9341 TFT Display CSD52 connected to ILI9341 TFT Display SCKD51 connected to ILI9341 TFT Display SDID22 - D33 connected to Pushbutton Pin 4 (out) (one button per pin)LED connected to Arduino Mega 2560 3V3VCC connected to Arduino Mega 2560 5VGND connected to Arduino Mega 2560 GNDRESET connected to Arduino Mega 2560 D8 PWMDC/RS connected to Arduino Mega 2560 D9 PWMCS connected to Arduino Mega 2560 D10 PWMSCK connected to Arduino Mega 2560 D52SDI connected to Arduino Mega 2560 D51Pin 1 (in) connected to Arduino Mega 2560 GNDPin 2 connected to Arduino Mega 2560 D7 PWM (only for one specific pushbutton)Pin 3 (out) connected to Arduino Mega 2560 GND (common for all pushbuttons)Pin 4 (out) connected to Arduino Mega 2560 D22 - D33 (one button per pin)#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>
#include <SPI.h>
// TFT display setup (connect appropriately to your setup)
#define TFT_CS 10
#define TFT_RST 9 // Or set to -1 and connect to Arduino RESET pin
#define TFT_DC 8
#define TFT_MOSI 11
#define TFT_CLK 13
#define TFT_MISO 12
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST);
const int masterButtonPin = 7;
const int voteButtons[12] = {22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33};
int voteCounts[12] = {0}; // Vote counts for each candidate
bool votingStarted = false;
const char* candidateNames[12] = {
"Candidate A", "Candidate B", "Candidate C", "Candidate D",
"Candidate E", "Candidate F", "Candidate G", "Candidate H",
"Candidate I", "Candidate J", "Candidate K", "Candidate L"
};
void setup() {
Serial.begin(9600);
// Initialize TFT display
tft.begin();
tft.setRotation(3); // Set rotation (adjust for your layout)
tft.fillScreen(ILI9341_BLACK);
tft.setTextSize(2);
tft.setTextColor(ILI9341_WHITE);
// Master button and voting buttons
pinMode(masterButtonPin, INPUT_PULLUP);
for (int i = 0; i < 12; i++) {
pinMode(voteButtons[i], INPUT_PULLUP);
}
// Initial display message
tft.setCursor(0, 0);
tft.println("Ready for voting");
}
void loop() {
if (digitalRead(masterButtonPin) == LOW && !votingStarted) {
votingStarted = true;
tft.fillScreen(ILI9341_BLACK);
tft.setCursor(0, 0);
tft.println("Voting Started");
delay(500); // Debounce delay
}
if (votingStarted) {
for (int i = 0; i < 12; i++) {
if (digitalRead(voteButtons[i]) == LOW) {
voteCounts[i]++;
displayVotes(); // Update the display with vote counts
delay(500); // Debounce delay to prevent double counts
}
}
}
}
void displayVotes() {
tft.fillScreen(ILI9341_BLACK); // Clear screen
tft.setCursor(0, 0); // Reset cursor position
for (int i = 0; i < 12; i++) {
tft.setCursor(0, i * 20); // Adjust line spacing
tft.print(candidateNames[i]);
tft.print(": ");
tft.println(voteCounts[i]); // Print the vote count for each candidate
}
}
This code is designed to run on the Arduino Mega 2560 and interfaces with the ILI9341 TFT display to show the voting results. The masterButtonPin is used to start the voting process, and the voteButtons array contains the pins connected to the voting buttons. When a button is pressed, the corresponding vote count is incremented and displayed on the screen. The displayVotes function updates the TFT display with the current vote counts for each candidate.