Certamen Machine Code
#include <Wire.h> // Library for I2C communication
#include <LiquidCrystal_I2C.h> // Library for LCD
LiquidCrystal_I2C lcd = LiquidCrystal_I2C(0x27, 16, 2);
int buttonStateG1 = 0;
int buttonStateG2 = 0;
int buttonStateG3 = 0;
int buttonStateG4 = 0;
int buttonStateB1 = 0;
int buttonStateB2 = 0;
int buttonStateB3 = 0;
int buttonStateB4 = 0;
int buttonStateY1 = 0;
int buttonStateY2 = 0;
int buttonStateY3 = 0;
int buttonStateY4 = 0;
int r = 0;
void setup() {
pinMode(2, INPUT); //
pinMode(3, INPUT);
pinMode(4, INPUT);
pinMode(5, INPUT);
pinMode(6, INPUT);
pinMode(7, INPUT);
pinMode(8, INPUT);
pinMode(9, INPUT);
pinMode(10, INPUT);
pinMode(11, INPUT);
pinMode(12, INPUT);
pinMode(13, INPUT);
lcd.init();
lcd.backlight();
}
void loop() {
buttonStateG1 = digitalRead(2);
buttonStateG2 = digitalRead(3);
buttonStateG3 = digitalRead(4);
buttonStateG4 = digitalRead(5);
buttonStateB1 = digitalRead(6); //start of blue team
buttonStateB2 = digitalRead(7);
buttonStateB3 = digitalRead(8);
buttonStateB4 = digitalRead(9);
buttonStateY1 = digitalRead(10); //start of yellow team
buttonStateY2 = digitalRead(11);
buttonStateY3 = digitalRead(12);
buttonStateY4 = digitalRead(13);
lcd.setCursor(0, 0);
if (buttonStateG1 == 1 && r == 0) {
for (;;) {
lcd.print("G1 Pressed ");
lcd.setCursor(0, 1);
lcd.print(" Please restart ");
int r = 1;
}}
if (buttonStateG2 == 1 && r == 0) {
for (;;) {
lcd.print ("G2 Pressed ");
lcd.setCursor(0,1);
lcd.print(" Please restart ");
int r = 1;
}}
if (buttonStateG3 == 1 && r == 0) {
for (;;) {
lcd.print ("G3 Pressed ");
lcd.setCursor(0,1);
lcd.print(" Please restart ");
int r = 1;
}}
if (buttonStateG4 == 1 && r == 0) {
for (;;) {
lcd.print ("G4 Pressed ");
lcd.setCursor(0,1);
lcd.print(" Please restart ");
int r = 1;
}}
if (buttonStateB1 == 1 && r == 0) {
for (;;) {
lcd.print("B1 Pressed ");
lcd.setCursor(0, 1);
lcd.print(" Please restart ");
int r = 1;
}}
if (buttonStateB2 == 1 && r == 0) {
for (;;) {
lcd.print ("B2 Pressed ");
lcd.setCursor(0,1);
lcd.print(" Please restart ");
int r = 1;
}}
if (buttonStateB3 == 1 && r == 0) {
for (;;) {
lcd.print ("B3 Pressed ");
lcd.setCursor(0,1);
lcd.print(" Please restart ");
int r = 1;
}}
if (buttonStateB4 == 1 && r == 0) {
for (;;) {
lcd.print ("B4 Pressed ");
lcd.setCursor(0,1);
lcd.print(" Please restart ");
int r = 1;
}}
if (buttonStateY1 == 1 && r == 0) {
for (;;) {
lcd.print("Y1 Pressed ");
lcd.setCursor(0, 1);
lcd.print(" Please restart ");
int r = 1;
}}
if (buttonStateY2 == 1 && r == 0) {
for (;;) {
lcd.print ("Y2 Pressed ");
lcd.setCursor(0,1);
lcd.print(" Please restart ");
int r = 1;
}}
if (buttonStateY3 == 1 && r == 0) {
for (;;) {
lcd.print ("Y3 Pressed ");
lcd.setCursor(0,1);
lcd.print(" Please restart ");
int r = 1;
}}
if (buttonStateY4 == 1 && r == 0) {
for (;;) {
lcd.print ("Y4 Pressed ");
lcd.setCursor(0,1);
lcd.print(" Please restart ");
int r = 1;
}}
if (buttonStateG2 == 0 && buttonStateG1 == 0 && r == 0 && buttonStateG3 == 0 && buttonStateG4 == 0 && buttonStateB1 == 0 && buttonStateB2 == 0 && buttonStateB3 == 0 && buttonStateB4 == 0 && buttonStateY1 == 0 && buttonStateY2 == 0 && buttonStateY3 == 0 && buttonStateY4 == 0) {
lcd.print (" Reset ");
lcd.setCursor(0,1);
lcd.print(" Waiting... ");
}
}