#include<Wire.h>
#include<LiquidCrystal_I2C.h>
#include "FastLED.h"
#define NUM_LEDS 50
//// https://wokwi.com/projects/339120123052819027
//define I2C address......
LiquidCrystal_I2C lcd(0x27,16,4);
////Switches
int switch1 = 2; /// Bullseye target
int switch2 = 3; /// Wheel 2's
int switch3 = 4; //// top left red rollover
int switch4 = 6; //// kickout
int switch5 = 9; /// Ball launch switch- shooter lane
int switch6 = 12; /// Start switch
int switch7 = 7; ///
int switch8 = 10; /// wheel-Extra ball
int switch9 = 11; ///
int switch10 = 13; ///
int SwitchState1 = 1;
int SwitchState2 = 1;
int SwitchState3 = 1;
int SwitchState4 = 1;
int SwitchState5 = 1;
int SwitchState6 = 1;
int SwitchState7 = 1;
int SwitchState8 = 1;
int SwitchState9 = 1;
int SwitchState10 = 1;
/// LEDS
////// selinoids
int selinoid1 = 5; //// Wheel Selinoid
int selinoid2 = 8; //// Kick out Selinoid
bool wheel = false;
///scoring
int score1;
int score2;
int redmulti = 1;
int yellowmulti = 1;
///counting Balls
bool game = false;
bool ball1 = true;
bool ball2 = true;
bool ball3 = true;
int p1balls = 0;
int p2balls = 0;
int extraball = 0;
void setup()
{
Serial.begin(9600);
/// LCD stuff
lcd.init();
lcd.clear();
lcd.backlight();
/////Switches
pinMode(switch1, INPUT_PULLUP);
pinMode(switch2, INPUT_PULLUP);
pinMode(switch3, INPUT_PULLUP);
pinMode(switch4, INPUT_PULLUP);
pinMode(switch5, INPUT_PULLUP);
pinMode(switch6, INPUT_PULLUP);
pinMode(switch7, INPUT_PULLUP);
pinMode(switch8, INPUT_PULLUP);
pinMode(switch9, INPUT_PULLUP);
pinMode(switch10, INPUT_PULLUP);
///selinoid
pinMode(selinoid1, OUTPUT);
pinMode(selinoid2, OUTPUT);
////LEDS
}
void loop()
{
Generalscoring();
wheelscoring();
wheelspin();
balls();
balleject();
Gamestart();
multiplyer();
SwitchState1 = digitalRead(switch1);
SwitchState2 = digitalRead(switch2);
SwitchState3 = digitalRead(switch3);
SwitchState4 = digitalRead(switch4);
SwitchState5 = digitalRead(switch5);
SwitchState6 = digitalRead(switch6);
SwitchState7 = digitalRead(switch7);
SwitchState8 = digitalRead(switch8);
SwitchState9 = digitalRead(switch9);
SwitchState10 = digitalRead(switch10);
}
void Gamestart()
{
if (SwitchState6 == LOW && game == false)
{
lcd.clear();
delay (600);
lcd.setCursor(2,0);
lcd.print("Player 1");
lcd.setCursor(2,1);
lcd.print("Ball");
lcd.setCursor(7,1);
lcd.print("1");
lcd.setCursor(3,3);
lcd.print("RM YM");
ball1 = true;
ball2 = true;
ball3 = true;
game = true;
digitalWrite (selinoid2, HIGH);
delay (1200);
digitalWrite (selinoid2, LOW);
}
}
void balleject()
{
if (SwitchState4 == LOW && game == true)
{
delay (600);
digitalWrite (selinoid2, HIGH);
delay (1200);
digitalWrite (selinoid2, LOW);
}
}
void balls()
{
if (SwitchState5 == LOW ) /// shooter lane
{
delay (600);
p1balls = (p1balls+1);
}
else if (p1balls == 1 && ball1 == true)
{
lcd.setCursor(7,1);
lcd.print("1");
}
else if (p1balls == 2 && ball2 == true)
{
ball1 = false;
lcd.setCursor(7,1);
lcd.print("2");
}
else if (p1balls == 3 && ball3 == true)
{
ball2 = false;
lcd.setCursor(7,1);
lcd.print("3");
}
if (SwitchState4 == LOW && p1balls == 3)
{
lcd.setCursor(7,1);
lcd.print("game over");
p1balls = 0;
score1 = 0;
game = false;
}
}
void wheelspin()
{
if (wheel == true)
{
digitalWrite (selinoid1, HIGH);
delay (700);
digitalWrite (selinoid1, LOW);
wheel = false;
}
}
void multiplyer()
{
if (SwitchState1 == LOW && (redmulti <= 3)) /// switch bullseye
{
delay (200);
wheel = true;
redmulti = (redmulti + 1);
yellowmulti = (yellowmulti + 1);
lcd.setCursor(6,3);
lcd.print(redmulti);
lcd.setCursor(15,3);
lcd.print(yellowmulti);
}
else if (SwitchState1 == LOW && (redmulti >= 4) && redmulti < 54) /// switch bullseye
{
delay (200);
redmulti = (redmulti + 10);
yellowmulti = (yellowmulti + 10);
lcd.setCursor(6,3);
lcd.print(redmulti);
lcd.setCursor(15,3);
lcd.print(yellowmulti);
}
else if (SwitchState1 == LOW && (redmulti == 54)) /// switch bullseye
{
delay (200);
redmulti = (redmulti + 100);
yellowmulti = (yellowmulti + 100);
lcd.setCursor(6,3);
lcd.print(redmulti);
lcd.setCursor(15,3);
lcd.print(yellowmulti);
}
}
void wheelscoring()
{
if (SwitchState2 == LOW) /// 2's wheel
{
delay (200);
score1 = score1 + (2*yellowmulti);
lcd.setCursor(12,0);
lcd.print(score1);
}
if (SwitchState8 == LOW) //// extra ball
{
delay (200);
score1 = score1 + 25;
lcd.setCursor(12,0);
lcd.print(score1);
p1balls = p1balls - 1;
extraball = extraball +1;
lcd.setCursor(12,1);
lcd.print("EB");
lcd.setCursor(14,1);
lcd.print(extraball);
}
}
void Generalscoring()
{
if (SwitchState3 == LOW && (redmulti <= 3))
{
delay (200);
score1 = score1 + 50;
lcd.setCursor(12,0);
lcd.print(score1);
redmulti = (redmulti + 1);
lcd.setCursor(6,3);
lcd.print(redmulti);
}
else if (SwitchState3 == LOW && (redmulti >= 4) && redmulti < 54)
{
delay (200);
redmulti = (redmulti + 10);
lcd.setCursor(6,3);
lcd.print(redmulti);
}
else if (SwitchState3 == LOW && (redmulti == 54))
{
delay (200);
redmulti = (redmulti + 100);
lcd.setCursor(6,3);
lcd.print(redmulti);
}
}