Ok so the serial monitor is set to print out the values just as they are in the matrix and I have changed the last row to be more recognisable. I get three rows printed out on three lines for three spins, so it is easy to recognise the string of values and compare them to the matrix.
If I leave one spin running for a while it will wrap around and chug along that row. The first spin starts on the first value but actually only the second value registers. All good, throw the switch and observe the triple flash... wait a while turn the switch again.
The second spin does not start from the begining of the second row, rather it starts on the column following the stop position of the first spin, and likewise with the third spin.
So reading the matrix, the spinCount just drops down a line with each spin, no reset to the start of the row.
Heres my code;
//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]);
}
}
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;
// 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 += 1;
if (spinCount == 25) spinCount = 0; //Checking if variable spinCount needs wrapping around
flash(600, 200, symbols[wheelToUse][spinCount]); // quick flash for each moving symbol
Serial.print(symbols[wheelToUse][spinCount]);
}