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

Multi Buttons example ? #1

Open
cod3r-dev opened this issue Jan 19, 2020 · 1 comment
Open

Multi Buttons example ? #1

cod3r-dev opened this issue Jan 19, 2020 · 1 comment

Comments

@cod3r-dev
Copy link

cod3r-dev commented Jan 19, 2020

If we have 30 buttons ? How i will loop on them ?

thanks

@RayPS
Copy link

RayPS commented Jan 19, 2022

Probably not the best but this is how I did

Throttle Key0 = Throttle(16, INPUT_PULLUP);
Throttle Key1 = Throttle(9, INPUT_PULLUP);
Throttle Key2 = Throttle(10, INPUT_PULLUP); 
Throttle Key3 = Throttle(0, INPUT_PULLUP); 
Throttle Key4 = Throttle(5, INPUT_PULLUP);
Throttle Key5 = Throttle(3, INPUT_PULLUP);
Throttle Key6 = Throttle(14, INPUT_PULLUP);
Throttle Key7 = Throttle(12, INPUT_PULLUP);
Throttle Key8 = Throttle(13, INPUT_PULLUP);
Throttle Key9 = Throttle(2, INPUT_PULLUP);
Throttle Key10 = Throttle(4, INPUT_PULLUP);

Throttle *keys[] = {&Key0, &Key1, &Key2, &Key3, &Key4, &Key5, &Key6, &Key7, &Key8, &Key9, &Key10};
void loop() {
  for (Throttle *key: keys) {
    key->update();
  }

  if (Key0.fell()) {
    // Do something...
  }
  if (Key1.fell()) {
    // Do something...
  }
  if (Key2.fell()) {
    // Do something...
  }
  // .....and so on
}

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