I have a fairly simply sketch that will eventually be running a clock (yes another one XD). All the code (attached) behaves exactly as it should but after approximately 5 minutes the setup function re-run's.
I'm using a V3 Nano in a breadboard setup, no external devices at this time (although later a few 74HC595N will drive the output, and a bluetooth module will provide input). I'm connecting via USB and using the Serial Monitor to view the output, all on a Win7Pro PC.
Is this normal behavior ? Or is it indicative of a problem ?
I'm not normally a C programmer and I haven't done electronics for a few many years so it's quite possible I've FUBAR'ed.
byte registers[5]; //6 bytes for the output of the 6 8bit registers
The comment is wrong.
for (int i = 0; i < 6; i++) //re-initialise all the registers
{ registers[i] = 0xFF; };
Although this statement looks like the comment was right but the declaration was wrong.
int upperLimit = 58; //Highest valid ASCII value +1 (57 = "9")
int input = 0; //Value entered
inputTimeoutAt = millis() + inputTimeoutInterval;
//Set new input timeout
input = Serial.read(); //Get this input
switch (inputPtr) //Get max valid value for current
{
case 0: //First digit 0-2
upperLimit = 51;
break;
case 1: //If first digit was 2 then second is 0-3
if (inputBuffer[0] == 2)
{ upperLimit = 52; };
break;
case 2: //Third digit 0-5
upperLimit = 54;
break;
}; //Second and fourth 0-9 (set by declaration)
if (input > 47 && input < upperLimit) //If digit in valid range
{
inputBuffer[inputPtr] = input - 48; //Turn character into number and store in
Since 48 = '0', this code would be a lot more readable if you got rid of the ASCII values and used character values.