arduino-tachometer
arduino-tachometer copied to clipboard
LEDs go off as they go up?
Hi I love this it’s great - I’m just wanting to tweak it a bit so that when the next led is illuminated the previous goes out - can you specify a rpm range somehow as the values for each led? Like ‘[4000-4999],[5000-5999],[6000]’ Thank you!
Just modify the setLedState method:
void setLedState(int rpm) {
setGlobalState(LOW);
// If rpm is over REV_LIMITER_RPM, all leds should be blinking at 200ms interval
if (rpm > REV_LIMITER_RPM) {
if (revLimiterOn) {
setGlobalState(LOW);
} else {
setGlobalState(HIGH);
}
revLimiterOn = !revLimiterOn;
return;
}
// Holds the index of the highest LED to turn on
int maxPin = -1;
for (int i = 0; i < PINS_COUNT; i++) {
if (rpm >= LED_SWITCH_RPM[i]) {
// Set the LED index
maxPin = i;
} else {
// No sense in continuing the loop since the remaining RPM values are too high
break;
}
}
// Only turn on the LED we flagged above
if (maxPin > -1) {
digitalWrite(maxPin, HIGH);
}
}