Hi my program reads in an array and outputs the logic level to a corresponding LED. This produces a sequence and is meant to repeat a set number of times, however it never stops. I'm assuming its stuck in a loop and is not properly exiting.
Im new to programming so go easy. This is my program:
#include <stdlib.h>
#include <stdio.h>
// constants won't change. They're used here to set pin numbers:
const int switch2 = 2; // the number of the pushbutton pin
const int switch3 = 3;
const int switch4 = 4;
const int switch5 = 5;
// the variables that will change:
int switchState2 = 0; // variable for reading the switch status
int time = 10;
int ledPins[] = {6,7,8,9,10,11,12,13};
int pinCount = 8;
void setup() {
// initialize the LED pin as an output:
for (int column_number = 0; column_number < pinCount; column_number++) {
pinMode(ledPins[column_number], OUTPUT);
// initialize the switch pin as an input:
pinMode(switch2, INPUT);
}
}
//when switch 2 is pressed this is the sequence for the leds:
int array2[16][8] = {{1,0,0,0,0,0,0,0},
{1,1,0,0,0,0,0,0},
{1,1,1,0,0,0,0,0},
{1,1,1,1,0,0,0,0},
{1,1,1,1,1,0,0,0},
{1,1,1,1,1,1,0,0},
{1,1,1,1,1,1,1,0},
{1,1,1,1,1,1,1,1},
{1,1,1,1,1,1,1,0},
{1,1,1,1,1,1,0,0},
{1,1,1,1,1,0,0,0},
{1,1,1,1,0,0,0,0},
{1,1,1,0,0,0,0,0},
{1,1,0,0,0,0,0,0},
{1,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0}};
void switch2a(int array2[16][8], int MAX_ROW, int repeat)
{
int row_count = 0;
int end_of_column = 7;
for (int repeat_count = 0; repeat_count < repeat;)
for (int column_number = 0; column_number < 8; column_number++) {
// if the number in the matrix is equal to 1 then the led will turn on
if (array2[row_count][column_number] == 1)
{
// turn LED on:
digitalWrite(ledPins[column_number], HIGH);
delay(time);
}
else {
// turn LED off:
digitalWrite(ledPins[column_number], LOW);
delay(time);
}
//this checks if it is at the end of the sequence
if (column_number == end_of_column) {
column_number = -1;
row_count++;
}
if (row_count == MAX_ROW) {
row_count = 0;
repeat_count++;
}
}
}
void loop()
{
switch2a(array2,16,10);
}
As you can see I wanted the sequence to repeat 10 times.
Any help is most appreciated.