I am a total newbie to arduino and have used it to control the programmable led strips in a touchscreen jukebox I have built. The first sketch changes colour patterns through button presses 1 to 4 but I want to add the RGB Active sketch to change the lights via the Gravity analog sound sensor via button press 5.
I have tried to work it out but keep ketting compile errors so any help would be appreciated.
Sketch 1
#include <FastLED.h>
#define LED_PIN 7
#define BTN_PIN 5
#define NUM_LEDS 122
#define BRIGHTNESS 200
#define LED_TYPE WS2812B
#define COLOR_ORDER GRB
#define UPDATES_PER_SECOND 200
CRGB leds[NUM_LEDS];
int counter = 0;
int buttonState = 0;
CRGBPalette16 currentPalette;
TBlendType currentBlending;
extern CRGBPalette16 myRedWhiteBluePalette;
extern const TProgmemPalette16 myRedWhiteBluePalette_p PROGMEM;
void setup() {
delay( 1500 ); // power-up safety delay
FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
FastLED.setBrightness( BRIGHTNESS );
pinMode(BTN_PIN, INPUT_PULLUP);
Serial.begin(9600);
currentPalette = RainbowColors_p;
currentBlending = LINEARBLEND;
}
void loop()
{
ChangePalettePeriodically();
static uint8_t startIndex = 0;
startIndex = startIndex + 1; /* motion speed */
FillLEDsFromPaletteColors( startIndex);
FastLED.show();
FastLED.delay(1000 / UPDATES_PER_SECOND);
}
void FillLEDsFromPaletteColors( uint8_t colorIndex)
{
uint8_t brightness = 200;
for( int i = 0; i < NUM_LEDS; i++) {
leds[i] = ColorFromPalette( currentPalette, colorIndex, brightness, currentBlending);
colorIndex += 3;
}
}
void ChangePalettePeriodically()
{
Serial.println(digitalRead(BTN_PIN));
// check if the pushbutton is pressed. If it is, the buttonState is HIGH:
if(digitalRead(BTN_PIN) == LOW) {
counter = counter + 1;
delay(130);
}
if(counter == 4) {
counter = 0;
}
if( counter == 0) { currentPalette = RainbowColors_p; currentBlending = LINEARBLEND; }
if( counter == 1) { currentPalette = RainbowStripeColors_p; currentBlending = LINEARBLEND; }
if( counter == 2) { currentPalette = CloudColors_p; currentBlending = LINEARBLEND; }
if( counter == 3) { currentPalette = myRedWhiteBluePalette_p; currentBlending = NOBLEND; }
if( counter == 4) { currentPalette = myRedWhiteBluePalette_p; currentBlending = LINEARBLEND; }
}
// This function fills the palette with totally random colors.
void SetupTotallyRandomPalette()
{
for( int i = 0; i < 16; i++) {
currentPalette[i] = CHSV( random8(), 255, random8());
}
}
void SetupBlackAndWhiteStripedPalette()
{
// 'black out' all 16 palette entries...
fill_solid( currentPalette, 16, CRGB::Black);
// and set every fourth one to white.
currentPalette[0] = CRGB::White;
currentPalette[4] = CRGB::White;
currentPalette[8] = CRGB::White;
currentPalette[12] = CRGB::White;
}
// This function sets up a palette of purple and green stripes.
void SetupPurpleAndGreenPalette()
{
CRGB purple = CHSV( HUE_PURPLE, 255, 255);
CRGB green = CHSV( HUE_GREEN, 255, 255);
CRGB black = CRGB::Black;
currentPalette = CRGBPalette16(
green, green, black, black,
purple, purple, black, black,
green, green, black, black,
purple, purple, black, black );
}
const TProgmemPalette16 myRedWhiteBluePalette_p PROGMEM =
{
CRGB::Red,
CRGB::Gray, // 'white' is too bright compared to red and blue
CRGB::Blue,
CRGB::Black,
CRGB::Red,
CRGB::Gray,
CRGB::Blue,
CRGB::Black,
CRGB::Red,
CRGB::Red,
CRGB::Gray,
CRGB::Gray,
CRGB::Blue,
CRGB::Blue,
CRGB::Black,
CRGB::Black
};
Sketch 2
//NOTE:-ADJUST/SET BY POTENTIOMETER OF SOUND SENSOR IF LESS NUMBER OF PATTERN OBSERVE
#include <FastLED.h>
int r=152;
int g=0;
int b=10;
#define LED_PIN 7 //CONNECT DATA PIN OF PIXEL WITH 5 NUMBER PIN OF ARDUINO
#define NUM_LEDS 122 //CHANGE THE VALUE IF YOU WANT TO USE DIFFRENT NUMBER OF LED IN YOUR STRIP,HERE IN MY STRIP NUMBER OF LED IS 60 SO I SET IT 60.
CRGB leds[NUM_LEDS];
CRGB led[NUM_LEDS];
int s=0;
void setup() {
FastLED.addLeds<WS2812B, LED_PIN, GRB>(leds, NUM_LEDS);
for (int i = NUM_LEDS/2; i >= 0; i--)
{
leds[i] = CRGB ( r,g,b);
leds[NUM_LEDS-i] = CRGB (r,g,b );
delay(40);
FastLED.show();
}
Serial.begin(9600);
pinMode(A0,INPUT);
}
void loop()
{
s=analogRead(A0);
s=s*2;
// Serial.println(s);
// delay(50);
if((s>=450)&&(s<=550))
{
leds[(NUM_LEDS/2)-1]=CRGB (0, 0, 255);
leds[NUM_LEDS/2]=CRGB (0, 0, 255);
}
else if((s>=400)&&(s<=450))
{
leds[(NUM_LEDS/2)-1]=CRGB (153, 153, 0);
leds[NUM_LEDS/2]=CRGB (153, 153, 0);
}
else if((s>=350)&&(s<=400))
{
leds[(NUM_LEDS/2)-1]=CRGB (255, 50, 255);
leds[NUM_LEDS/2]=CRGB (255, 50, 255);
}
else if((s>=300)&&(s<=350))
{
leds[(NUM_LEDS/2)-1]=CRGB (10, 25, 217);
leds[NUM_LEDS/2]=CRGB (10, 25, 217);
}
else if((s>=276)&&(s<=300))
{
leds[(NUM_LEDS/2)-1]=CRGB (50, 50, 150);
leds[NUM_LEDS/2]=CRGB (50, 50, 150);
}
else if((s>=250)&&(s<=275))
{
leds[(NUM_LEDS/2)-1]=CRGB (230, 0, 10);
leds[NUM_LEDS/2]=CRGB (230, 0, 10);
}
else if((s>=235)&&(s<=250))
{
leds[(NUM_LEDS/2)-1]=CRGB (0, 160, 0);
leds[NUM_LEDS/2]=CRGB (0, 160, 0);
}
else if((s>=200)&&(s<=230))
{
leds[(NUM_LEDS/2)-1]=CRGB (1, 0, 1);
leds[NUM_LEDS/2]=CRGB (1, 0, 1);
}
else
{
leds[(NUM_LEDS/2)-1] = CRGB ( r,s-100,b);
leds[NUM_LEDS/2] = CRGB ( r,s-100,b);
}
for (int i = 0; i <= ((NUM_LEDS/2)-2); i++)
{
leds[i] = leds[i+1];
leds[NUM_LEDS-1-i] = leds[(NUM_LEDS)-i-2];
}
FastLED.show();
delay(25);
}