Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

Arduino Mega 2560 Based Voting System with TFT Display Interface

View and Edit Project In Cirkit DesignerImage of Arduino Mega 2560 Based Voting System with TFT Display Interface

Circuit Documentation

Summary

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.

Component List

Arduino Mega 2560

ILI9341 TFT Display

Pushbuttons (14 instances)

Wiring Details

Arduino Mega 2560

ILI9341 TFT Display

Pushbuttons

Documented Code

#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.