#include <RTClib.h>
#include <iostream>
#include <ctime>
RTC_DS3231 rtc;
const int buttonPins[] = {22, 21, 17, 16, 0, 2};
const int numButtons = sizeof(buttonPins) / sizeof(buttonPins[0]);
// Array to hold the state of each button
int buttonStates[numButtons];
char daysOfWeek[7][12] = {
"Sunday",
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday"
};
void setup()
{
Serial.begin(115200);
if (!rtc.begin()) {
Serial.println("Couldn't find RTC. Dead now.");
while(1);
}
// Initialize each button pin as an input with internal pull-up resistor
for (int i = 0; i < numButtons; i++) {
pinMode(buttonPins[i], INPUT_PULLUP);
buttonStates[i] = HIGH; // Default state is HIGH (not pressed)
}
Serial.print("Number of buttons : ");
Serial.println(numButtons);
}
void loop() {
//int buttonPressed = GetVote();
//current date/time based on current system
DateTime now = rtc.now();
String ttime = String(daysOfWeek[now.dayOfTheWeek()]) + " " +
String(now.day()) + "-" +
String(now.month()) + "-" +
String(now.year()) + " " +
String(now.hour()) + ":" +
String(now.minute()) + ":" +
String(now.second()) ;
Serial.print("The local date and time is: ");
Serial.println(ttime);
delay(1000);
}
int lastpressed = -1;
int GetVote()
{
int pressedVote = getPressedVoteBtn ();
if(pressedVote != -1 && lastpressed != pressedVote)
{
Serial.print("Vote button ");
Serial.print(pressedVote);
Serial.println(" pressed");
lastpressed = pressedVote;
//get who selected
}
return -1;
}
int getPressedVoteBtn()
{
for (int i = 0; i < numButtons; i++) {
int currentState = digitalRead(buttonPins[i]);
if (currentState == LOW)
{
while (digitalRead(buttonPins[i]) == LOW);
return buttonPins[i];
}
}
return -1;
}