Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "FastLED.h"
- #define PIN_SLIDE_POT_A0 A0 // input pin of the slide pot
- #define PIN_SLIDE_POT_A1 A1 // input pin of the slide pot
- #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
- #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
- #define NUM_LEDS1 10 // add number of LEDs of your RGB LED strip
- #define NUM_LEDS2 10 // add number of LEDs of your RGB LED strip
- #define PIN_LED1 3 // digital output PIN that is connected to DIN of the RGB LED strip
- #define PIN_LED2 4
- #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...
- CRGB rgb_led1[NUM_LEDS1]; // color array of the LED RGB strip
- CRGB rgb_led2[NUM_LEDS2]; // color array of the LED RGB strip
- void setup() {
- Serial.begin(9600);
- pinMode(PIN_SLIDE_POT_A0, INPUT);
- pinMode(PIN_SLIDE_POT_A1, INPUT);
- FastLED.addLeds<WS2812B, PIN_LED1>(rgb_led1, NUM_LEDS1);
- FastLED.addLeds<WS2812B, PIN_LED2>(rgb_led2, NUM_LEDS2);
- Serial.println("Setup done.");
- }
- void loop() {
- // 1) Analog value of slide pot is read
- int value_slide_pot_a0 = analogRead(PIN_SLIDE_POT_A0);
- Serial.print("Slide 1 Pot value: ");
- Serial.println(value_slide_pot_a0);
- int value_slide_pot_a1 = analogRead(PIN_SLIDE_POT_A1);
- Serial.print("Slide 2 Pot value: ");
- Serial.println(value_slide_pot_a1);
- // 2) Analog value is mapped from slide pot range (analog input value) to led range (number of LEDs)
- int num_leds1_switchedon = map(value_slide_pot_a0, 0, MAX_SLIDE1_POT_ANALGOG_READ_VALUE, 0, NUM_LEDS1);
- int num_leds2_switchedon = map(value_slide_pot_a1, 0, MAX_SLIDE2_POT_ANALGOG_READ_VALUE, 0, NUM_LEDS2);
- // 3) Light up the LEDs
- // Only LEDs are switched on which correspond to the area left of the slide knob
- for (int i = 0; i < num_leds1_switchedon; ++i) {
- rgb_led1[i] = LED_COLOR;
- }
- // LEDs are switched off which correspond to the area right of the slide knob
- for (int i = num_leds1_switchedon; i < NUM_LEDS1; ++i) {
- rgb_led1[i] = CRGB::Black;
- // Only LEDs are switched on which correspond to the area left of the slide knob
- for (int i = 0; i < num_leds2_switchedon; ++i) {
- rgb_led2[i] = LED_COLOR;
- }
- // LEDs are switched off which correspond to the area right of the slide knob
- for (int i = num_leds2_switchedon; i < NUM_LEDS2; ++i) {
- rgb_led2[i] = CRGB::Black;
- }
- FastLED.show();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement