I am Making an Voting Machine So How Could I Disable Switches So That I Can Receive One Vote at a time

Post your solution for other forum members who are interested in a voting machine.

1 Like

that would be an example, with a button to "arm" the voting after a vote has been completed

click to see the code
#include <Toggle.h>                         // https://github.com/Dlloydev/Toggle

const byte votePins[] = {8, 7, 6};
const byte readyPin = 2;
const byte buttonCnt = sizeof votePins / sizeof * votePins;
const byte buzzerPin = A0;
Toggle buttons[buttonCnt];
Toggle readyButton;

enum {READY, VOTED} mode = READY;

void setup() {
  pinMode(buzzerPin, OUTPUT);
  readyButton.begin(readyPin);
  for (byte i = 0; i < buttonCnt; i++) buttons[i].begin(votePins[i]);
  Serial.begin(115200);
}

void loop() {
  switch (mode) {
    case READY:
      for (byte i = 0; i < buttonCnt; i++) {
        buttons[i].poll();
        if (buttons[i].onPress()) {
          tone(buzzerPin, 1500, 50); delay(50);
          tone(buzzerPin, 600, 50);  delay(50);
          tone(buzzerPin, 1500, 50);          
          Serial.print("VOTED. Selected => "); Serial.write('A' + i); Serial.println();
          mode = VOTED;
          break;
        }
      }
      break;

    case VOTED: // we wait for the reset to ready
      readyButton.poll();
      if (readyButton.onPress()) {
        tone(buzzerPin, 500, 100);
        mode = READY;
      }
      break;

  }
}


(ground wires hidden to keep the drawing readable)

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.