muse4665

Untitled

Apr 14th, 2021
289
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const int pot0 = 0;
  2. const int pot1 = 1;
  3. const int leds[] = {9, 8, 7, 6, 5, 4, 3, 2};
  4. const double ledsLength = sizeof(leds)/sizeof(leds[0]);
  5.  
  6. void setup() {
  7.     for(int i = 0; i < ledsLength; i++) {
  8.         pinMode(leds[i], OUTPUT);
  9.     }
  10.     pinMode(pot0, INPUT);
  11.     pinMode(pot1, INPUT);
  12. }
  13.  
  14. void loop() {
  15.     switch ((int)(analogRead(pot0) * (3.0/1024))) {
  16.         case 0:
  17.             handleSingleLight();
  18.             break;
  19.         case 1:
  20.             handleLightWipe();
  21.             break;
  22.         case 2:
  23.             handleSearchLight();
  24.             break;
  25.     }
  26. }
  27.  
  28. void handleSingleLight() {
  29.     int lightSelect = (int)(analogRead(pot1) * (ledsLength/1024));
  30.     for(int i = 0; i < ledsLength; i++){
  31.         digitalWrite(i, i == lightSelect);
  32.     }
  33. }
  34.  
  35. void handleLightWipe() {
  36.     int lightSelect = (int)(analogRead(pot1) * (ledsLength/1024));
  37.     for(int i = 0; i < ledsLength; i++){
  38.         digitalWrite(i, i <= lightSelect);
  39.     }
  40. }
  41.  
  42. void handleSearchLight() {
  43.     int lightSelect = (int)(analogRead(pot1) * (ledsLength/1024));
  44.     for(int i = 0; i < ledsLength; i++){
  45.         digitalWrite(i, abs(lightSelect - i) <= 1);
  46.     }
  47. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×