Hello, I'm trying to define the 55 leds into 3 different colors from one potentiometer. would like to get white, green, red at different ranges from the pot (white at 0-70, green 70-800, red 800-1023)
//trying to define the 55 leds into 3 different colors from one potentiometer.
// trying to get white, green, red at different ranges from the pot (white at 0-70, green 70-800, red //800-1023)
#include "FastLED.h"
#define PIN_SLIDE_POT_A A0 // pot
#define MAX_SLIDE_POT_ANALGOG_READ_VALUE 1023 // (5volt)
#define NUM_LEDS 55
//#define PIN_LED 3
//#define DATA_PIN 3
#define LED_TYPE WS2812B
#define COLOR_ORDER GRB
CRGB leds[NUM_LEDS];
#define MAX_SLIDE_VALUE 1024
#define MAX_MAP_OUTPUT 110
#define LED_PIN 3
// doesnt work , max_map_output used instead ---> #define BRIGHTNESS 50
CRGB rgb_led[NUM_LEDS]; // array
void setup() {
delay(3000);
Serial.begin(9600);
//maybe add
FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS);
pinMode(PIN_SLIDE_POT_A, INPUT);
FastLED.addLeds<WS2812B, LED_PIN>(rgb_led, NUM_LEDS);
}
void loop() {
// Read analog pot
int value_slide_pot_a = analogRead(PIN_SLIDE_POT_A);
Serial.print("Slide Pot value: ");
Serial.println(value_slide_pot_a);
//maybe try
int value_slide_a = analogRead(PIN_SLIDE_POT_A);
int SLIDER_VALUE = map(value_slide_a, 0, MAX_SLIDE_VALUE, 0, MAX_MAP_OUTPUT);
// pot to range leds
int num_leds_switchedon = map(value_slide_pot_a, 0, MAX_SLIDE_POT_ANALGOG_READ_VALUE, 0, NUM_LEDS);
// leds lower range pot
for (int i = 0; i < num_leds_switchedon; ++i) {
rgb_led[i] = CHSV(320,255,SLIDER_VALUE);
//leds[i] = CHSV(180,255,SLIDER_VALUE);
}
///try three colors
// LEDs color from high range pot
for (int i = num_leds_switchedon; i < NUM_LEDS; ++i) {
rgb_led[i] = CHSV(350,255,SLIDER_VALUE);
//leds[i] = CHSV(50,255,SLIDER_VALUE);
}
FastLED.show();
}
ok thanks, new to this again after a while . am I on the right path with the following?
// if the analog value is 0-80, turn on the white led:
if (analogRead > 80) {
rgb_led[24] = CHSV(1,255,SLIDER_VALUE);
} else {
rgb_led[80] = CHSV(220,255,SLIDER_VALUE);
}
I have a 55 led strip. I'm trying to have the 0-6 leds white color, leds 7-37 green, leds 37 - 55 red. all controlled by one pot's 0 - 1023 value, white would turn on gradually increasing 0-110 , yellow 110-720, and red 720- 1023.
// if the analog value is 0-80, turn on the white led:
int potValue = analogRead (PIN_SLIDE_POT_A);
if ( potValue > 0 && potValue < 80)
{
// turn on the white led
}
I did not map the analog read value. The above is to show method and syntax.
You need to put the work in when translating from English to code. The uC is very fussy about syntax. Just look everything up in the reference and then make sure your syntax matches.
You can copy and paste their example syntax and then comment it out in the code so that you have it right there to copy from.