#include <LiquidCrystal.h>
const int buttonPin = 8;
int buttonState = LOW;
int lastButtonState = LOW; // Assume button starts unpressed (PULLUP)
unsigned long lastTapTime = 0;
int tapCount = 0;
bool flag = true;
int targetSequence[] = {0,1,0};
int currentPosition = 0;
int randomNumOne, randomNumTwo, randomNumThree;
double moneyCount = 50;
LiquidCrystal lcdOne(22, 23, 4, 5, 6, 7);
LiquidCrystal lcdTwo(24, 25, 10, 11, 12, 13);
LiquidCrystal lcdThree(14, 15, 16, 17, 18, 19);
void setup() {
Serial.begin(9600);
Serial.print("£"); // Try direct symbol (works in some IDEs)
Serial.println(moneyCount);
randomSeed(analogRead(A0));
pinMode(buttonPin, INPUT); // Button to GND
lcdOne.begin(16, 2);
lcdTwo.begin(16, 2);
lcdThree.begin(16, 2);
}
void loop() {
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH && flag == true && tapCount != 7) {
singleClick();
delay(50);
flag = false;
checkSequence(randomNumOne, randomNumTwo, randomNumThree);
}
if(buttonState == LOW){
flag = true;
delay(50);
}
// Detect button press (LOW due to PULLUP)
if (buttonState == LOW && lastButtonState == HIGH) {
// Check if taps are within 0.85s of each other
if (millis() - lastTapTime < 850) {
tapCount++;
} else {
tapCount = 1; // Reset if too slow
}
lastTapTime = millis(); // Update last tap time
}
// If 7 taps are registered, show "7" after 0.85s delay
if (tapCount == 7 && millis() - lastTapTime >= 850) {
showSeven();
tapCount = 0; // Reset counter
}
lastButtonState = buttonState;
}
void showSeven() {
if (currentPosition == 0){
lcdOne.clear();
int displayNumberOne = 7;
lcdOne.print(displayNumberOne);
if(displayNumberOne == targetSequence[0]){
currentPosition = currentPosition + 1;
}
return;
}
if (currentPosition == 1){
lcdTwo.clear();
lcdTwo.print("7");
}
if (currentPosition == 2){
lcdThree.clear();
lcdThree.print("7");
}
}
void singleClick(){
moneyCount = moneyCount - 1;
Serial.print("£"); // Try direct symbol (works in some IDEs)
Serial.println(moneyCount);
randomNumOne = random(0, 2);
randomNumTwo = random(0, 2); // Generates a number between 0-999
randomNumThree = random(0, 2); // Generates a number between 0-999
lcdOne.clear();
lcdOne.setCursor(0, 1); // Move to 2nd line
lcdOne.print(randomNumOne);
lcdTwo.clear();
lcdTwo.setCursor(0, 1);
lcdTwo.print(randomNumTwo);
lcdThree.clear();
lcdThree.setCursor(0, 1);
lcdThree.print(randomNumThree);
}
void checkSequence(int one, int two, int three){
if (one == targetSequence[0] && two == targetSequence[1] && three == targetSequence[2]){
Serial.println("You Win Collect £60");
moneyCount = moneyCount + 60;
Serial.print("£"); // Try direct symbol (works in some IDEs)
Serial.println(moneyCount);
}
}