#include <FastLED.h>
#include <Wire.h>
#define LED_PIN 8
#define NUM_LEDS 16
#define BRIGHTNESS 255
#define LED_TYPE WS2812
#define COLOR_ORDER GRB
CRGB leds[NUM_LEDS];
#define UPDATES_PER_SECOND 10000
CRGBPalette16 currentPalette;
TBlendType currentBlending;
extern const CRGBPalette16 CustomLavaColors_p = {
CRGB::DarkRed,CRGB::Red,CRGB::Red,CRGB::Orange,CRGB::Orange,CRGB::Red,CRGB::Red,CRGB::DarkRed,
CRGB::DarkRed,CRGB::Red,CRGB::Red,CRGB::Orange,CRGB::Orange,CRGB::Red,CRGB::Red,CRGB::DarkRed,
}; //custom lavacolors
CRGBPalette16 grad[4] {
CustomLavaColors_p,
ForestColors_p,
OceanColors_p,
RainbowColors_p
};// custompallette gradients
int dfdelay = 150;
int Rlvl=0;
int Glvl=0;
int Blvl=0;
int potpin ; // analog pin used to connect the potentiometer
int colorval; // variable to read the value from the analog pin
int colorpick;
int val;
int new_val ;
byte buttonPin;
const uint8_t buttonPins[] = {3, 4, 5};
int mode;
int nrs[3] = {
0, 0, 0
};//nrs
void setup() {
delay( 500 ); // power-up safety delay
Serial.begin(9600);
FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );//make leds entity
FastLED.setBrightness( BRIGHTNESS );//set brightness
//FastLED.show();
currentBlending = LINEARBLEND;
for (byte i = 0; i <3 ; i++) {
pinMode(buttonPins[i], INPUT_PULLUP);
}
}
byte readButtons() {
while (true) {
for (byte i = 0; i <3; i++) {
byte buttonPin = buttonPins[i];
if (digitalRead(buttonPin) == LOW) {
if(i==0){//3 switch gradient
mode=1;
};
if (i==1){//4 colorpick
mode=2;
};
if (i==2){//5 colorval
mode=3;
};
return i;
};
if(mode==3){//blue
Serial.println("Color val");
val = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023)
val = map(val, 0, 1023, 0, 255); // scale it to use it with the servo (value between 0 and 180)
colorval= val;
nrs[colorpick]=colorval;
RGB_color(nrs[0],nrs[1],nrs[2]);
Serial.println(colorval);
}
else if(mode==2){//blue
Serial.println("Color pick");
val = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023)
val = map(val, 0, 1023, 0, 2); // scale it to use it with the servo (value between 0 and 180)
colorpick=val;
Serial.println(val);
}
else if(mode==1){
val = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023)
val = map(val, 0, 1023, 0,3); // scale it to
Serial.println(val);
Gradient(val);
//Serial.println(gradients[val]);
};
}
}
// delay(1);
};
void loop() {
if(val!=new_val&&mode!=4){
//Serial.println("changed");
new_val=val;
return ;
};
readButtons();
};
int RGB_color(int red_light_value, int green_light_value, int blue_light_value) {
nrs[0] = red_light_value;
nrs[1] = green_light_value;
nrs[2] = blue_light_value;
for ( int i = 0; i < NUM_LEDS; i++) {
leds[i].setRGB(nrs[0], nrs[1], nrs[2]);
};//end for int i
FastLED.show();
};//end rgb
void FillLEDsFromPaletteColors( uint8_t colorIndex)
{
for ( int i = 0; i < NUM_LEDS; i++) {
leds[i] = ColorFromPalette(currentPalette, colorIndex, BRIGHTNESS, currentBlending);
colorIndex += 1;
};//end for
FastLED.show();
};//end fill colors from pallete
void Gradient(int n) {
currentPalette = grad[n];
static uint8_t startIndex = 0;
startIndex = startIndex + 1; /* motion speed */
FillLEDsFromPaletteColors(startIndex);
FastLED.delay( dfdelay );
FastLED.show();
};//gradient