My program, below, only prints "New Phrase:" three times. As far as I can tell, it should continue printing this line to the serial port every ten seconds, forever. I will post the code in the next message.
int ledInputPin = 13; // choose the pin for the LED
int ledMimicPin = 12; // choose the pin for the LED
int inputPin = 2; // choose the input pin (for a pushbutton)
int val = 0; // variable for reading the pin status
int beatStart[MAXIMUM_BEATS];
int beatDuration[MAXIMUM_BEATS];
int phraseLengthMillis = 1000 * 10;
int phraseTimestamp = -1;
int currentBeat = 0;
int repeatDelay = 1000 * 5;
boolean playback = false;
boolean beatOn = false;
int pauseStart = -1;
void setup() {
Serial.begin(9600);
pinMode(ledInputPin, OUTPUT); // declare LED as output
pinMode(ledMimicPin, OUTPUT); // declare LED as output
pinMode(inputPin, INPUT); // declare pushbutton as input
initArray(beatStart, MAXIMUM_BEATS, 0);
initArray(beatDuration, MAXIMUM_BEATS, 0);
}
int initArray(int a[], int arrayLength, int value) {
for(int i = 0; i < arrayLength; i++) {
a = value;
}*
return arrayLength;* } void loop(){
if (phraseTimestamp < 0)*
{*
phraseTimestamp = millis();*
currentBeat = 0;*
}*
else if (phraseTimestamp + phraseLengthMillis < millis())*
That way, it can hold enough bits to represent actual amount of milliseconds.
An int can hold 32,767 milliseconds (which explains the three prints because 3*10000 = 30000) as opposed to unsigned long that holds 4,294,967,295 milliseconds (enough for ~430000 loops).