OK lets leave that while loop a while... I accept that convention is good to follow.
Returning to the larger coding layout. We have to call values from a 2 dimensional matrix, we are using this instead of three separate matrixes because it makes the code more compact and we like to use for loops to increment through slabs of code or stings of values that are following the same process.
For me this is putting a lot of conceptual juggling balls in the air, but hey it was my choice to join the circus.
Let me try to list the loops and functions so far:
1 - In the setup, we have a for loop to name and arm 10 pins as LED outputs - Check, I get it. It runs through once and job done, onto the void-loop which cycles as long as the processor has power on
2 - In the void loop, we have a for loop that counts through the three wheels, it calls up the flash function which contains the last value from the spin function and flashes that value - Check I get it - this loop runs from an open array with 3 places that will, once the nest is built correspond to Spin 0, Spin1 and Spin2 - needs building
3 - The flash function declares three variables, an on time, off time, and a "token" placeholder for a call to the symbol array that will count through 25 symbols comprising 10 LED pins that will turn on and off when called
To call the first line in the matrix we use [0][spinCount] meaning we are on the first row of the matrix and counting along. We will need a counter to tick that first matrix over.
I have been using the serial.print to track the spinCount, and I have kept it in the code. I have changed it to give me a read of the pin numbers by calling up the matrix. When I do get onto wheel 2 the serial monitor will confirm.
I am feeling like I almost know what to do, but I can't figure out where to start. i know you have already told me what to do, but I need to tease it apart. Maybe a single point to address first? Thanks Mike.
//multi-array of 3 reels of 25 symbols made up of 10 different tokens
byte symbols[3][25] = {
{2, 3, 2, 4, 5, 6, 3, 2, 7, 2, 8, 9, 3, 4, 5, 2, 3, 2, 10, 2, 11, 2, 3, 9, 5 },
{10, 4, 9, 2, 3, 4, 9, 5, 6, 4, 9, 7, 8, 4, 9, 11, 9, 3, 5, 9, 5, 3, 2, 9, 4 },
{10, 4, 9, 2, 3, 4, 9, 5, 6, 4, 9, 7, 8, 4, 9, 11, 9, 3, 5, 9, 5, 3, 2, 9, 4 }
};
byte wheel[3]; //wheel array for storing the stop token for three reel spins
void setup() {
for (int i = 2; i < 12; i++) { // declare pin numbers for 10 symbols
pinMode(i, OUTPUT); //declare pins as outputs
}
pinMode(15, INPUT_PULLUP); //declare pin 15 as an input with 5V pullup resitor
}
void loop() {
Serial.begin(9600);
//reel stop function displaying each stop token passed up from spin function
wheel[0] = spin();
for (int i = 0; i < 3; i ++) {
flash(200, 200, wheel[0]);
}
while (1) { } // stop, press reset to start
}
// flash function calls up each token LED & turns on then off
void flash( int onTime, int offTime, byte token) {
digitalWrite(token, HIGH); // will turn on the LED
delay(onTime); // so you can see it
digitalWrite(token, LOW); // will turn off the LED
delay(offTime); // so you can see it off
}
int spin() {
// loop along 25 smbol row in array
static int spinCount = 0;
// waiting...
while (digitalRead(15) == HIGH) { } // do nothing until the switch is moved
// spin action starts here
while (digitalRead(15) == LOW) { //checking if input remains low before advancing count
Serial.print(symbols[0][spinCount] );
spinCount += 1;
if (spinCount == 25) spinCount = 0; //Checking if variable spinCount needs wrapping around
flash(600, 200, symbols[0][spinCount]); // quick flash for each moving symbol
if (spinCount == 0) Serial.println(" "); //start a new line on printout
}
return symbols[0][spinCount]; // send back to begining of void loop the symbol/token it landed on
}