Advertisement
Guest User

Untitled

a guest
Nov 20th, 2021
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.68 KB | None | 0 0
  1. #include "FastLED.h"
  2.  
  3. #define PIN_SLIDE_POT_A0 A0 // input pin of the slide pot
  4. #define PIN_SLIDE_POT_A1 A1 // input pin of the slide pot
  5. #define MAX_SLIDE1_POT_ANALGOG_READ_VALUE 700 // maximum voltage as analog-to-digital converted value, depends on the voltage level of the VCC pin. Examples: 5V = 1023; 3.3V ~700
  6. #define MAX_SLIDE2_POT_ANALGOG_READ_VALUE 700 // maximum voltage as analog-to-digital converted value, depends on the voltage level of the VCC pin. Examples: 5V = 1023; 3.3V ~700
  7.  
  8. #define NUM_LEDS1 10 // add number of LEDs of your RGB LED strip
  9. #define NUM_LEDS2 10 // add number of LEDs of your RGB LED strip
  10. #define PIN_LED1 3 // digital output PIN that is connected to DIN of the RGB LED strip
  11. #define PIN_LED2 4
  12. #define LED_COLOR CRGB::DarkOrchid // see https://github.com/FastLED/FastLED/wiki/Pixel-reference for a full list, e.g. CRGB::AliceBlue, CRGB::Amethyst, CRGB::AntiqueWhite...
  13.  
  14. CRGB rgb_led1[NUM_LEDS1]; // color array of the LED RGB strip
  15. CRGB rgb_led2[NUM_LEDS2]; // color array of the LED RGB strip
  16.  
  17. void setup() {
  18.   Serial.begin(9600);
  19.  
  20.   pinMode(PIN_SLIDE_POT_A0, INPUT);
  21.   pinMode(PIN_SLIDE_POT_A1, INPUT);
  22.   FastLED.addLeds<WS2812B, PIN_LED1>(rgb_led1, NUM_LEDS1);  
  23.   FastLED.addLeds<WS2812B, PIN_LED2>(rgb_led2, NUM_LEDS2);
  24.  
  25.   Serial.println("Setup done.");
  26.  }
  27.  
  28. void loop() {
  29.   // 1) Analog value of slide pot is read
  30.   int value_slide_pot_a0 = analogRead(PIN_SLIDE_POT_A0);
  31.   Serial.print("Slide 1 Pot value: ");
  32.   Serial.println(value_slide_pot_a0);
  33.   int value_slide_pot_a1 = analogRead(PIN_SLIDE_POT_A1);
  34.   Serial.print("Slide 2 Pot value: ");
  35.   Serial.println(value_slide_pot_a1);
  36.  
  37.   // 2) Analog value is mapped from slide pot range (analog input value) to led range (number of LEDs)
  38.   int num_leds1_switchedon = map(value_slide_pot_a0, 0, MAX_SLIDE1_POT_ANALGOG_READ_VALUE, 0, NUM_LEDS1);
  39.   int num_leds2_switchedon = map(value_slide_pot_a1, 0, MAX_SLIDE2_POT_ANALGOG_READ_VALUE, 0, NUM_LEDS2);
  40.  
  41.    // 3) Light up the LEDs
  42.   // Only LEDs are switched on which correspond to the area left of the slide knob
  43.   for (int i = 0; i < num_leds1_switchedon; ++i) {
  44.     rgb_led1[i] = LED_COLOR;
  45.   }  
  46.   // LEDs are switched off which correspond to the area right of the slide knob
  47.   for (int i = num_leds1_switchedon; i < NUM_LEDS1; ++i) {
  48.     rgb_led1[i] = CRGB::Black;
  49.   }
  50.   // Only LEDs are switched on which correspond to the area left of the slide knob
  51.   for (int i = 0; i < num_leds2_switchedon; ++i) {
  52.     rgb_led2[i] = LED_COLOR;
  53.   }  
  54.   // LEDs are switched off which correspond to the area right of the slide knob
  55.   for (int i = num_leds2_switchedon; i < NUM_LEDS2; ++i) {
  56.     rgb_led2[i] = CRGB::Black;
  57.   }
  58.   FastLED.show();
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement