I have managed to create the following test sketch to simulate my real program and try to implement the gear shit indicator led flash. The timings have been slowed down for easier reading in the serial monitor.
byte temp;
byte Display_RPM;
byte ShiftIndicator = 5;
unsigned long result = 6902;
long previousMillis = 0;
byte flash(long Interval)
{
long currentMillis = millis();
if(currentMillis - previousMillis > Interval)
{
previousMillis = currentMillis;
return 1;
}
else
{
return 0;
}
}
void setup()
{
Serial.begin(9600);
}
void loop()
{
temp = result/1000;
Display_RPM = ~((1 << (8 - temp)) -1);
if(temp >= ShiftIndicator && flash(1000) == 1)
{
bitSet(Display_RPM, 0);
Serial.println(Display_RPM, BIN);
}
else
{
Serial.println(Display_RPM, BIN);
}
delay(900);
}
Is there a better way todo this or is this ok? The useful thing is that i can use the flash routine for other things too.