#include <LiquidCrystal.h>
class Symbol {
public:
String name;
int id;
byte byteArray[8][8];
int xY[8][2];
};
LiquidCrystal lcdOne(22, 23, 4, 5, 6, 7);
LiquidCrystal lcdTwo(24, 25, 10, 11, 12, 13);
LiquidCrystal lcdThree(14, 15, 16, 17, 18, 19);
LiquidCrystal* lcds[] = { &lcdOne, &lcdTwo, &lcdThree };
int randomNums[3] = {0, 0, 0};
const int buttonPin = 8;
bool lastButtonState = HIGH;
int randomNumOne = 0;
int randomNumTwo = 0;
int randomNumThree = 0;
bool isSpun = false;
double money = 10;
//Create Symbol objects
Symbol cherrys;
Symbol diamond;
void setup() {
Serial.begin(9600);
lcdOne.begin(16, 2);
lcdTwo.begin(16, 2);
lcdThree.begin(16, 2);
pinMode(buttonPin, INPUT);
randomSeed(analogRead(A0));
//Cherrys
cherrys.name = "cherrys";
cherrys.id = 1;
byte cherrysByteArray[8][8] = {
{ B00000, B00000, B00001, B00011, B00011, B00010, B00011, B00001 },
{ B00000, B11100, B11110, B11111, B11111, B11111, B00110, B11100 },
{ B00000, B00000, B00000, B00000, B10000, B01000, B00100, B00011 },
{ B00000, B00000, B00000, B00000, B00000, B00000, B00000, B00000 },
{ B00001, B00011, B00011, B00010, B00011, B00001, B00000, B00000 },
{ B11100, B11110, B11111, B11111, B00111, B11110, B11100, B00000 },
{ B00010, B00100, B01000, B10000, B00000, B00000, B00000, B00000 },
{ B10000, B01000, B01000, B00000, B00000, B00000, B00000, B00000 }
};
int cherrysXY[8][2] = {
{0, 6}, {0, 7}, {0, 8}, {0, 9},
{1, 6}, {1, 7}, {1, 8}, {1, 9}
};
for (int i = 0; i < 8; i++) {
for (int j = 0; j < 8; j++) {
cherrys.byteArray[i][j] = cherrysByteArray[i][j];
}
cherrys.xY[i][0] = cherrysXY[i][0];
cherrys.xY[i][1] = cherrysXY[i][1];
}
//Diamond
diamond.name = "diamond";
diamond.id = 2;
byte diamondByteArray[8][8] = {
{ B00000, B00110, B01110, B01100, B01100, B01100, B11111, B01100 },
{ B00000, B00011, B00111, B01100, B01100, B01100, B11111, B01100 },
{ B00000, B10000, B11000, B01100, B01100, B01100, B11111, B01100 },
{ B00000, B00000, B00000, B00000, B00000, B00000, B00000, B00000 },
{ B01100, B11111, B01100, B01100, B01100, B00111, B00011, B00000 },
{ B01100, B11111, B01100, B01100, B01100, B11000, B10000, B00000 },
{ B01100, B11111, B01100, B01100, B01100, B11100, B11000, B00000 },
{ B00000, B00000, B00000, B00000, B00000, B00000, B00000, B00000 }
};
int diamondXY[8][2] = {
{0, 6}, {0, 7}, {0, 8}, {0, 9},
{1, 6}, {1, 7}, {1, 8}, {1, 9}
};
for (int i = 0; i < 8; i++) {
for (int j = 0; j < 8; j++) {
diamond.byteArray[i][j] = diamondByteArray[i][j];
}
diamond.xY[i][0] = diamondXY[i][0];
diamond.xY[i][1] = diamondXY[i][1];
}
}
void loop() {
checkButtonPress();
if (isSpun == true) {
isSpun = false;
lcdOne.clear();
lcdTwo.clear();
lcdThree.clear();
for(int i = 0; i < 3; i++){
switch (randomNums[i]) {
case 1:
displaySymbol(*lcds[i], cherrys);
break;
case 2:
displaySymbol(*lcds[i], diamond);
break;
case 3:
lcds[i]->setCursor(0, 0);
lcds[i]->print("Random: 3");
break;
case 4:
lcds[i]->setCursor(0, 0);
lcds[i]->print("Random: 4");
break;
case 5:
lcds[i]->setCursor(0, 0);
lcds[i]->print("Random: 5");
break;
case 6:
lcds[i]->setCursor(0, 0);
lcds[i]->print("Random: 6");
break;
default:
break;
}
}
checkForWin(randomNums[0], randomNums[1], randomNums[2]);
}
}
void displaySymbol(LiquidCrystal &lcd, Symbol &symbol) {
// Load custom characters
for (int i = 0; i < 8; i++) {
lcd.createChar(i, symbol.byteArray[i]);
}
for (int i = 0; i < 8; i++) {
int row = symbol.xY[i][0];
int col = symbol.xY[i][1];
lcd.setCursor(col, row);
lcd.write(i);
}
}
void checkButtonPress(){
bool currentButtonState = digitalRead(buttonPin);
if (currentButtonState == HIGH && lastButtonState == LOW) {
for (int i = 0; i < 3; i++) {
randomNums[i] = random(1, 7);
}
isSpun = true;
}
lastButtonState = currentButtonState;
delay(50);
}
void checkForWin(int randomNumOne, int randomNumTwo, int randomNumThree){
if(randomNumOne == randomNumTwo && randomNumOne == randomNumThree){
money += 10;
Serial.println(money);
delay(2000);
}
}