OK, Thanks Mike for telling me what I need to know, but also taking the time to try and figure out how I am losing track.
I get the concept of trading variables - I just find it tricky to do, keeping track...
In the code as it works now in the flash function we end up with this line
return symbols[wheelToUse][spinCount[wheelToUse]];
So I thought this call to the symbols matrix could now be used as the basis of the final flash sequence.
So I copy and paste it into a new for loop incrementing the wheeltoUse index back up near the top of the loop function. Now this term precedes the spin function and perhaps for that reason I now get an error message telling me that:
'spinCount' was not declared in this scope. So, no problem I just transport the declaration too:
static int spinCount [] = {0,0,0};
At least the code now compiles, but something is missing... spinCount has been developed in the spin function so I need to track down the 'freshest' version of what spinCount signifies and declare it afresh. So it seems natural to apply the added variable [wheelToUse] but that throws the last term in the flash function with this error message: invalid types 'int[byte {aka unsigned char}]' for array subscript...
Seems I am missing something [again]
So here is where I am at:
//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 },
{2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 3, 4, 5, 6, 7, 8 }
};
byte wheel[3] = {0, 0, 0}; //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
Serial.begin(9600); // needs to be in setup and not loop
}
void loop() {
for (int j = 0; j < 3 ; j++ ) { //calling up 3 wheels indexing through matrix rows
// you need to call spin here and tell it what wheel it is on
wheel[j] = spin(j); // we are passing a paramater to spin so we have to
//change the spin function to cope with this
for (int i = 0; i < 3; i ++) { // flashing symbol passed back from spin function
flash(200, 200, wheel[j]);
}
}
//for (byte wheelToUse = 0; wheelToUse < 3; ++wheelToUse) {
//static int spinCount [] = {0,0,0};
//int spinCount = spinCount[wheelToUse];
// flash(1000, 200, symbols[wheelToUse][spinCount[wheelToUse]]);
// }
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(int wheelToUse) { // need to tell spin to accept a symbol
// loop along 25 smbol row in array
static int spinCount [] = {0,0,0};
// waiting...
while (digitalRead(15) == HIGH) { } // do nothing until the switch is moved
// spin action starts here
Serial.println(" "); //start a new line on printout
while (digitalRead(15) == LOW) { //checking if input remains high before advancing count
spinCount[wheelToUse] += 1;
if (spinCount[wheelToUse] == 25) spinCount[wheelToUse] = 0; //Checking if variable spinCount needs wrapping around
flash(600, 200, symbols[wheelToUse][spinCount[wheelToUse]]); // quick flash for each moving symbol
Serial.print(symbols[wheelToUse][spinCount[wheelToUse]]);
}
return symbols[wheelToUse][spinCount[wheelToUse]]; // send back the symbol/token it landed on
}