#include <LiquidCrystal.h>
LiquidCrystal lcdOne(22, 23, 4, 5, 6, 7);
LiquidCrystal lcdTwo(24, 25, 10, 11, 12, 13);
LiquidCrystal lcdThree(14, 15, 16, 17, 18, 19);
const int buttonPin = 8;
bool lcdOneCorrect = false;
bool lcdTwoCorrect = false;
bool lcdThreeCorrect = false;
bool allCorrect = false;
int buttonState = LOW;
int lastButtonState = LOW;
unsigned long lastTapTime = 0;
int tapCount = 0;
bool flag = true;
int targetSequence[] = {0,0,0};
int currentPosition = 0;
int randomNumOne, randomNumTwo, randomNumThree;
double moneyCount = 50;
// Cherry, letterCount = 6, symbolNumber = 0
byte cherry1x8[] = { B00010, B00100, B01000, B10000, B00000, B00000, B00000, B0000 };
byte cherry0x6[] = { B00000, B00000, B00001, B00011, B00011, B00010, B00011, B00001 };
byte cherry0x7[] = { B00000, B11100, B11110, B11111, B11111, B11111, B00110, B11100 };
byte cherry0x8[] = { B00000, B00000, B00000, B00000, B10000, B01000, B00100, B00011 };
byte cherry1x6[] = { B00001, B00011, B00011, B00010, B00011, B00001, B00000, B00000 };
byte cherry1x7[] = { B11100, B11110, B11111, B11111, B00111, B11110, B11100, B00000 };
byte cherry1x9[] = { B10000, B01000, B01000, B00000, B00000, B00000, B00000, B00000 };
// Currency, letterCount = 8, symbolNumber = 1
byte currency1x8[] = { B01100, B11111, B01100, B01100, B01100, B11100, B11000, B00000 };
byte currency0x6[] = { B00000, B00110, B01110, B01100, B01100, B01100, B11111, B01100 };
byte currency0x7[] = { B00000, B00011, B00111, B01100, B01100, B01100, B11111, B01100 };
byte currency0x8[] = { B00000, B10000, B11000, B01100, B01100, B01100, B11111, B01100 };
byte currency1x6[] = { B01100, B11111, B01100, B01100, B01100, B00111, B00011, B00000 };
byte currency1x7[] = { B01100, B11111, B01100, B01100, B01100, B11000, B10000, B00000 };
void setup() {
Serial.begin(9600);
Serial.print("£");
Serial.println(moneyCount);
randomSeed(analogRead(A0));
pinMode(buttonPin, INPUT);
lcdOne.begin(16, 2);
lcdTwo.begin(16, 2);
lcdThree.begin(16, 2);
}
void loop() {
buttonState = digitalRead(buttonPin);
if(allCorrect == false){
if(buttonState == HIGH && flag == true && tapCount != 6){
singleClick();
delay(50);
flag = false;
checkSequence(randomNumOne, randomNumTwo, randomNumThree);
}
if(buttonState == LOW){
flag = true;
delay(50);
}
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 (tapCount == 6 && millis() - lastTapTime >= 850) {
cherrySix();
tapCount = 0;
}
if (tapCount == 7 && millis() - lastTapTime >= 850) {
currencySix();
tapCount = 0;
}
lastButtonState = buttonState;
}
else{
return;
}
}
// Cherry
void cherrySix() {
// lcdOne
if (currentPosition == 0){
lcdOne.clear();
placeCherryLcdOne();
if(0 == targetSequence[0]){
lcdOneCorrect = true;
currentPosition = currentPosition + 1;
}
return;
}
// lcdTwo
if (currentPosition == 1){
lcdTwo.clear();
placeCherryLcdTwo();
if(0 == targetSequence[1]){
lcdTwoCorrect = true;
currentPosition = currentPosition + 1;
}
return;
}
// lcdThree
if (currentPosition == 2){
lcdThree.clear();
placeCherryLcdThree();
if(0 == targetSequence[2]){
lcdThreeCorrect = true;
currentPosition = currentPosition + 1;
}
return;
}
}
// Currency
void currencyEight(){
// lcdOne
if (currentPosition == 0){
lcdOne.clear();
placeCurrencyLcdOne();
if(1 == targetSequence[0]){
lcdOneCorrect = true;
currentPosition = currentPosition + 1;
}
return;
}
// lcdTwo
if (currentPosition == 1){
lcdTwo.clear();
placeCurrencyLcdOne();
if(1 == targetSequence[1]){
lcdTwoCorrect = true;
currentPosition = currentPosition + 1;
}
return;
}
// lcdThree
if (currentPosition == 2){
lcdThree.clear();
placeCurrencyLcdOne();
if(1 == targetSequence[2]){
lcdThreeCorrect = true;
currentPosition = currentPosition + 1;
}
return;
}
}
void singleClick(){
moneyCount = moneyCount - 1;
Serial.print("£"); // Try direct symbol (works in some IDEs)
Serial.println(moneyCount);
randomNumOne = random(0, 5);
randomNumTwo = random(0, 5); // Generates a number between 0-999
randomNumThree = random(0, 5); // Generates a number between 0-999
if(lcdOneCorrect == false){
lcdOne.clear();
lcdOne.setCursor(0, 1); // Move to 2nd line
if(randomNumOne == 0){
placeCherryLcdOne();
}
else if(randomNumOne == 1){
placeCurrencyLcdOne();
}
else{
lcdOne.print(randomNumOne);
}
}
if(lcdTwoCorrect == false){
lcdTwo.clear();
lcdTwo.setCursor(0, 1);
if(randomNumTwo == 0){
placeCherryLcdTwo();
}
else if(randomNumTwo == 1){
placeCurrencyLcdTwo();
}
else{
lcdTwo.print(randomNumTwo);
}
}
if(lcdThreeCorrect == false){
lcdThree.clear();
lcdThree.setCursor(0, 1);
if(randomNumThree == 0){
placeCherryLcdThree();
}
else if(randomNumThree == 1){
placeCurrencyLcdThree();
}
else{
lcdThree.print(randomNumThree);
}
}
}
void checkSequence(int one, int two, int three){
if (one == targetSequence[0] && two == targetSequence[1] && three == targetSequence[2]){
allCorrect = true;
Serial.println("You Win Collect £60");
moneyCount = moneyCount + 60;
Serial.print("£");
Serial.println(moneyCount);
}
}
// Place symbols
// Place Cherry
// Cherry for lcdOne
void placeCherryLcdOne(){
lcdOne.createChar(1, cherry1x8);
lcdOne.setCursor(8, 1);
lcdOne.write(1);
lcdOne.createChar(2, cherry0x6);
lcdOne.setCursor(6, 0);
lcdOne.write(2);
lcdOne.createChar(3, cherry0x7);
lcdOne.setCursor(7, 0);
lcdOne.write(3);
lcdOne.createChar(4, cherry0x8);
lcdOne.setCursor(8, 0);
lcdOne.write(4);
lcdOne.createChar(5, cherry1x6);
lcdOne.setCursor(6, 1);
lcdOne.write(5);
lcdOne.createChar(6, cherry1x7);
lcdOne.setCursor(7, 1);
lcdOne.write(6);
lcdOne.createChar(7, cherry1x9);
lcdOne.setCursor(9, 1);
lcdOne.write(7);
}
// Cherry for lcdTwo
void placeCherryLcdTwo(){
lcdTwo.createChar(1, cherry1x8);
lcdTwo.setCursor(8, 1);
lcdTwo.write(1);
lcdTwo.createChar(2, cherry0x6);
lcdTwo.setCursor(6, 0);
lcdTwo.write(2);
lcdTwo.createChar(3, cherry0x7);
lcdTwo.setCursor(7, 0);
lcdTwo.write(3);
lcdTwo.createChar(4, cherry0x8);
lcdTwo.setCursor(8, 0);
lcdTwo.write(4);
lcdTwo.createChar(5, cherry1x6);
lcdTwo.setCursor(6, 1);
lcdTwo.write(5);
lcdTwo.createChar(6, cherry1x7);
lcdTwo.setCursor(7, 1);
lcdTwo.write(6);
lcdTwo.createChar(7, cherry1x9);
lcdTwo.setCursor(9, 1);
lcdTwo.write(7);
}
// Cherry for lcdThree
void placeCherryLcdThree(){
lcdThree.createChar(1, cherry1x8);
lcdThree.setCursor(8, 1);
lcdThree.write(1);
lcdThree.createChar(2, cherry0x6);
lcdThree.setCursor(6, 0);
lcdThree.write(2);
lcdThree.createChar(3, cherry0x7);
lcdThree.setCursor(7, 0);
lcdThree.write(3);
lcdThree.createChar(4, cherry0x8);
lcdThree.setCursor(8, 0);
lcdThree.write(4);
lcdThree.createChar(5, cherry1x6);
lcdThree.setCursor(6, 1);
lcdThree.write(5);
lcdThree.createChar(6, cherry1x7);
lcdThree.setCursor(7, 1);
lcdThree.write(6);
lcdThree.createChar(7, cherry1x9);
lcdThree.setCursor(9, 1);
lcdThree.write(7);
}
// Place Currency
// Currency for lcdOne
void placeCurrencyLcdOne(){
lcdOne.createChar(1, currency1x8);
lcdOne.setCursor(8, 1);
lcdOne.write(1);
lcdOne.createChar(2, currency0x6);
lcdOne.setCursor(6, 0);
lcdOne.write(2);
lcdOne.createChar(3, currency0x7);
lcdOne.setCursor(7, 0);
lcdOne.write(3);
lcdOne.createChar(5, currency0x8);
lcdOne.setCursor(8, 0);
lcdOne.write(5);
lcdOne.createChar(6, currency1x6);
lcdOne.setCursor(6, 1);
lcdOne.write(6);
lcdOne.createChar(7, currency1x7);
lcdOne.setCursor(7, 1);
lcdOne.write(7);
}
// Currency for lcdTwo
void placeCurrencyLcdTwo(){
lcdTwo.createChar(1, currency1x8);
lcdTwo.setCursor(8, 1);
lcdTwo.write(1);
lcdTwo.createChar(2, currency0x6);
lcdTwo.setCursor(6, 0);
lcdTwo.write(2);
lcdTwo.createChar(3, currency0x7);
lcdTwo.setCursor(7, 0);
lcdTwo.write(3);
lcdTwo.createChar(5, currency0x8);
lcdTwo.setCursor(8, 0);
lcdTwo.write(5);
lcdTwo.createChar(6, currency1x6);
lcdTwo.setCursor(6, 1);
lcdTwo.write(6);
lcdTwo.createChar(7, currency1x7);
lcdTwo.setCursor(7, 1);
lcdTwo.write(7);
}
// Currency for lcdThree
void placeCurrencyLcdThree(){
lcdThree.createChar(1, currency1x8);
lcdThree.setCursor(8, 1);
lcdThree.write(1);
lcdThree.createChar(2, currency0x6);
lcdThree.setCursor(6, 0);
lcdThree.write(2);
lcdThree.createChar(3, currency0x7);
lcdThree.setCursor(7, 0);
lcdThree.write(3);
lcdThree.createChar(5, currency0x8);
lcdThree.setCursor(8, 0);
lcdThree.write(5);
lcdThree.createChar(6, currency1x6);
lcdThree.setCursor(6, 1);
lcdThree.write(6);
lcdThree.createChar(7, currency1x7);
lcdThree.setCursor(7, 1);
lcdThree.write(7);
}