/*
Arduino | hardware-help
klausliker421 - Tuesday, March 24, 2026 8:31 PM
not to what i'm connecting it to
but the lcd works fine if the solenoids aren't plugged in
it's just that when they are it freaks out
so something about the extra stuff the solenoid/relay setup
does corrupts the data that the arduino sends to the lcd through the data pins
*/
#include <LiquidCrystal.h>
#include "StopwatchLib.h"
const int BUTTON1 = 6;
const int BUTTON2 = 5;
const int RELAY1 = 3;
const int RELAY2 = 4;
const int DETECTOR1 = A0;
const int DETECTOR2 = A1;
const int RS = 12, EN = 11, D4 = 10, D5 = 9, D6 = 8, D7 = 7;
int score = 0;
LiquidCrystal lcd(RS, EN, D4, D5, D6, D7);
Stopwatch stopwatch;
void showSplash() {
lcd.setCursor(1, 0);
lcd.print("klausliker421");
lcd.setCursor(5, 1);
lcd.print("Device");
delay(2000);
lcd.clear();
}
void setup() {
Serial.begin(9600);
lcd.begin(16, 2);
pinMode(BUTTON1, INPUT_PULLUP);
pinMode(BUTTON2, INPUT_PULLUP);
pinMode(RELAY1, OUTPUT);
pinMode(RELAY2, OUTPUT);
showSplash();
lcd.setCursor(0, 0);
lcd.print("a");
lcd.setCursor(0, 1);
lcd.print(score);
stopwatch.Reset();
}
void loop() {
//Serial.println(temp);
//if(analogRead(DETECTOR1) >= 1023)
if (digitalRead(BUTTON1) == LOW)
{
stopwatch.Update();
if (stopwatch.GetElapsed() > 750000)
{
score++;
//lcd.setCursor(0, 1);
//lcd.print("a");
stopwatch.Reset();
}
digitalWrite(RELAY2, HIGH);
//delay(50);
}
else
{
digitalWrite(RELAY2, LOW);
}
//if(analogRead(DETECTOR2) >= 1023)
if (digitalRead(BUTTON2) == LOW)
{
stopwatch.Update();
if (stopwatch.GetElapsed() > 750000)
{
score++;
//lcd.setCursor(0, 1);
//lcd.print(score);
stopwatch.Reset();
}
digitalWrite(RELAY1, HIGH);
//delay(50);
}
else
{
digitalWrite(RELAY1, LOW);
}
//Serial.println(analogRead(DETECTOR1));
if (analogRead(DETECTOR1) >= 1015)
{
lcd.clear();
lcd.setCursor(0, 0);
int rand = random(0, 1000);
lcd.print("game over");
lcd.print(rand);
//delay(25);
}
//lcd.setCursor(0,1);
//lcd.print(analogRead(DETECTOR1) + "-------");
}