Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LEDs go off as they go up? #4

Open
danwilderspin opened this issue Mar 6, 2022 · 1 comment
Open

LEDs go off as they go up? #4

danwilderspin opened this issue Mar 6, 2022 · 1 comment

Comments

@danwilderspin
Copy link

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!

@bosscube
Copy link

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);
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants