 # Simple Problem, Confusing Error... HELP!

So, the purpose of this code is to display a number by flashing a light… ie, the number 213 would be displayed as: flash-falsh… flash… flash-flash-flash.

This is designed to run as a loop, 20 cycles a second, turning the light on and off as needed. This sketch will be integrated into a much larger project (a rocket flight computer, the light flashing tells you the highest altitude).

So, for what ever reason, the sketch is stuck on the first digit. I ran diagnostics and found that while the “digit++” command at the bottom is occurring and increasing the value of “digit” by 1, “digit” goes back to a value of 1 when the loop restarts… help?

FYI: Instead of an LED flashing (I dont have one at the moment), it is transmitting something via Serial so the Serial light flashes…

``````//Example sketch for taking a 5 digit integer split it into digits and flash an LED to display them.
int integer = 32345;
int digit1;
int digit2;
int digit3;
int digit4;
int digit5;
int digit6;
int dig;
int digit;

int flashnum;
int fcount;
int count;
int dcount;
void setup()
{
//find digits
digit1 = integer/10000;
digit2 = (integer-10000*digit1)/1000;
digit3 = (integer-10000*digit1-1000*digit2)/100;
digit4 = (integer-10000*digit1-1000*digit2-100*digit3)/10;
digit5 = integer-10000*digit1-1000*digit2-100*digit3-10*digit4;
Serial.begin(9600);
Serial.println(digit1);
Serial.println(digit2);
Serial.println(digit3);
Serial.println(digit4);
Serial.println(digit5);
}

void loop()
{

delay(50);

if (digit=1)
{
dig = digit1;
}
else if (digit=2)
{
dig = digit2;
}
else if (digit=3)
{
dig = digit3;
}
else if (digit=4)
{
dig = digit5;
}
else if (digit=5)
{
if (count<60)
{
count++;
Serial.print("^^");
}
else
{

}
}

if (flashnum < dig)
{

if (fcount < 5)
{
Serial.print(flashnum);
fcount++;
}
else if (fcount < 10)
{
fcount++;
}
else if (fcount = 10)
{
fcount=0;
flashnum++;
}
}
else
{
if (dcount < 30)
{
dcount++;

}
else
{
flashnum=0;
if (digit=1)
{
digit=2;
}
else if (digit=2)
{
digit=3;
}
else if (digit=3)
{
digit=4;
}
else if (digit=4)
{
digit=5;
}
else if (digit=5)
{
digit=6;
}
else if (digit=6)
{
digit=7;
}
dcount=0;

}

}

}//end of loop
``````

if (digit=1)

Look here

#%^#%^\$#^!!!

Thanks, I have done that before!

rpmaurer:

# %\$^#\$%^\$#^!!!!!

Thanks, I have done that before!

You'll probably do it again, too. 8) So will I......