so... had a good 2.5 yr break from electronics, i'm quite experienced in a self taught sense. mostly my experience lies in audio and valves. i tried a bandit build back in 2015 and i got majorly hung up on the coin slot... fast forward to now and i think i might be better to get something "simpler" under my belt, i used to love playing the old pinball game on windows so you can probs guess my current project.
here is where i am so far:
#include <Wire.h> //initiailise the script by accessing needed libraries
#include <LiquidCrystal_I2C.h> // adds the iIIc lcd library
#define wiresda 20 //this pin is for iIIc data
#define wirescl 21 //this pin is for iIIc clock
#define launchdtct 2 //this pin is for detecting launch tube entry into play area
#define missionCon 3 //this pin is connected to launch pad rollover
#define ballDrain 8 //this pin is for the ball drain opto
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // assigns the pins for lcd use
int ballsRem = 3; //this is the value where balls remaining are stored
int currentscore = 0; // this is the value used to diplay the score
int gamestate = 0; // this bit will indicate wether the game is still running
int currentLevel = 0; // this int is used to store current level tag
int sel1 = 0;
int sel2 = 0;
int sel3 = 0;
int levelsel = 0; //a variable to be used for the level selection
int scoring = 0; // this will be used as a score modifier when each level advances
int score = 0; // this is where the current score will be stored
int highScore = 0;
void lightUp() {// a subroutine to flash lights on certain event triggers
}
void gameover (){// a subroutine to handle lives lost
}
void setup() {
pinMode (wiresda, OUTPUT);
pinMode (wirescl, OUTPUT);
pinMode (launchdtct, INPUT);
pinMode (missionCon, INPUT);
pinMode (ballDrain, INPUT);
digitalWrite(launchdtct, HIGH);
digitalWrite(missionCon, HIGH);
digitalWrite(ballDrain, HIGH);
}
void loop() {
if (launchdtct == LOW) {
gamestate++ ; //this will detct the ball and activate the game
}
if (gamestate >= 1) {
currentLevel = 1 ; //after detecting the ball lauch this puts the game into level selection 1
gamestate = 0; //reset the game status ready for next ball release
lightUp();
}
do {
if(ballDrain == LOW){
ballsRem --;
if(ballsRem >0){
lightUp();
currentLevel = 0;
scoring = 0;
if(score>highScore){
score = highScore;
}
}
else{
lightUp();
currentLevel --;
}
}
if (sel1 == LOW && sel2 == HIGH && sel3 == HIGH) {
levelsel = 2; // this detects level 2 being selected
}
if (sel1 == HIGH && sel2 == LOW && sel3 == HIGH) {
levelsel = 3; // this detects level 3 being selected
}
if (sel1 == HIGH && sel2 == HIGH && sel3 == LOW) {
levelsel = 4; // this detects level 4 being selected
}
if (sel1 == LOW && sel2 == LOW && sel3 == LOW) {
levelsel = 5; // this detects level 5 being selected
}
if (levelsel != 1 && missionCon == LOW) {
currentLevel = levelsel; // this confirms level by moving the selected number into the register
}
} while (currentLevel == 1); // this statement tells the do staement when to run
}
i'm still yet to map the layout for lights/outputs from the table, that is actually my next task so i can work out something for the scoring
in the mean time i had two major questions? firstly, is there any glaring mistakes in my level select code?
second, the game space cadet has a lot of input/outputs connecting to the table and the arduino mega (my board of choice for this) has a finite amount of storage. would i be right in assuming the best method would be to use two lots of two shift registers both in a matrix to control the lighting and a keyboard style matrix for my inputs?
thank you in advance