Breathing Light

Hi, I am new at this. I saw this project online and thought its cool. I want neopixel LED to fade in and out. I got the light hook up the the Arduino Uno, and plugged in a simple rainbow code, it works.

Then I tried to use the code below and it wouldn't compile. It just told me to come to this website to learn why it would not compile. Currently the light DI is in pin 6. Button input is in 2.

This is the code that won't compile. I would also like to add a button to operate the light.Can you tell me what I can do? I am new and i don't know programming, please go easy on me. I am just learning.

Thank you very much.

//***************************************************************
// Breathing effect
// Color shifts from hueA to hueB as it pulses.
//
// Set A and B to the same hue if you don't want the color to
// change. Saturation for the high and low can also be set.
//
// Marc Miller, 2015
// Updated Aug 2020 - removed delay, added dim8_video
//***************************************************************

#include <FastLED.h>
#define LED_TYPE WS2811 //WS2811, WS2812, WS2812B
#define COLOR_ORDER RGB
#define DATA_PIN 6
#define NUM_LEDS 12
#define BRIGHTNESS 255
CRGB leds[NUM_LEDS];

static float pulseSpeed = 0.5; // Larger value gives faster pulse.

uint8_t hueA = 15; // Start hue at valueMin.
uint8_t satA = 230; // Start saturation at valueMin.
float valueMin = 120.0; // Pulse minimum value (Should be less then valueMax).

uint8_t hueB = 95; // End hue at valueMax.
uint8_t satB = 255; // End saturation at valueMax.
float valueMax = 255.0; // Pulse maximum value (Should be larger then valueMin).

uint8_t hue = hueA; // Do Not Edit
uint8_t sat = satA; // Do Not Edit
float val = valueMin; // Do Not Edit
uint8_t hueDelta = hueA - hueB; // Do Not Edit
static float delta = (valueMax - valueMin) / 2.35040238; // Do Not Edit

//---------------------------------------------------------------
void setup(){
Serial.begin(115200); // Allows serial monitor output (check baud rate)
delay(2000); // Startup delay
FastLED.addLeds<LED_TYPE, DATA_PIN, COLOR_ORDER>(leds, NUM_LEDS);
FastLED.setBrightness(BRIGHTNESS);
FastLED.clear();
FastLED.show();
Serial.println("Setup done. \n");
}

//---------------------------------------------------------------
void loop(){
float dV = ((exp(sin(pulseSpeed * millis()/2000.0*PI)) -0.36787944) * delta);
val = valueMin + dV;
hue = map(val, valueMin, valueMax, hueA, hueB); // Map hue based on current val
sat = map(val, valueMin, valueMax, satA, satB); // Map sat based on current val

for (int i = 0; i < NUM_LEDS; i++) {
leds = CHSV(hue, sat, val);

  • // You can experiment with commenting out these dim8_video lines*
  • // to get a different sort of look.*
    leds.r = dim8_video(leds*.r);
    leds.g = dim8_video(leds.g);
    leds.b = dim8_video(leds.b);
    _ }
    FastLED.show();*_

} // end_main_loop

Please do this:

  • When you encounter an error, you'll see a button on the right side of the orange bar "Copy error messages" in the Arduino IDE (or the icon that looks like two pieces of paper at the top right corner of the black console window in the Arduino Web Editor). Click that button.
  • In a forum reply here, click on the reply field.
  • Click the </> button on the forum toolbar. This will add the forum's code tags markup to your reply.
  • Press "Ctrl + V". This will paste the error between the code tags.
  • Move the cursor outside of the code tags before you add any additional text to your reply.

If the text exceeds the forum's 9000 character limit, save it to a .txt file and post it as an attachment. If you click the "Reply" button here, you will see an "Attachments and other settings" link that will allow you to make the attachment.

@maemae187 - some of your code has been turned into italics because you did not enclose it in code tags

Please follow the advice on posting code given in Read this before posting a programming question

In particular note the advice to Auto format code in the IDE and to use code tags when posting code here as it prevents some combinations of characters in code being interpreted as HTML commands such as italics, bold or a smiley character, all of which render the code useless

If the code exceeds the 9000 character inline limit then attach it to a post

Ok, thank you all.

Rather than wasting another five minutes, couldn't you just have edited-in the code tags into your original post?

Also, please post any error messages you get from the compiler.

You can try this:

//***************************************************************
// Breathing effect
// Color shifts from hueA to hueB as it pulses.
//
// Set A and B to the same hue if you don't want the color to
// change.  Saturation for the high and low can also be set.
//
// Marc Miller, 2015
// Updated Aug 2020 - removed delay, added dim8_video
//***************************************************************

#include <FastLED.h>
#define LED_TYPE    WS2811  //WS2811, WS2812, WS2812B
#define COLOR_ORDER RGB
#define DATA_PIN 6
#define NUM_LEDS 12
#define BRIGHTNESS 255
CRGB leds[NUM_LEDS];

static float pulseSpeed = 0.5;  // Larger value gives faster pulse.

uint8_t hueA = 15;  // Start hue at valueMin.
uint8_t satA = 230;  // Start saturation at valueMin.
float valueMin = 120.0;  // Pulse minimum value (Should be less then valueMax).

uint8_t hueB = 95;  // End hue at valueMax.
uint8_t satB = 255;  // End saturation at valueMax.
float valueMax = 255.0;  // Pulse maximum value (Should be larger then valueMin).

uint8_t hue = hueA;  // Do Not Edit
uint8_t sat = satA;  // Do Not Edit
float val = valueMin;  // Do Not Edit
uint8_t hueDelta = hueA - hueB;  // Do Not Edit
static float delta = (valueMax - valueMin) / 2.35040238;  // Do Not Edit


//---------------------------------------------------------------
void setup()
{
    Serial.begin(115200);  // Allows serial monitor output (check baud rate)
    delay(2000);  // Startup delay
    FastLED.addLeds<LED_TYPE, DATA_PIN, COLOR_ORDER>(leds, NUM_LEDS);
    FastLED.setBrightness(BRIGHTNESS);
    FastLED.clear();
    FastLED.show();
    Serial.println("Setup done.  \n");
}


//---------------------------------------------------------------
void loop()
{
    float dV = ((exp(sin(pulseSpeed * millis()/2000.0*PI)) -0.36787944) * delta);
    val = valueMin + dV;
    hue = map(val, valueMin, valueMax, hueA, hueB);  // Map hue based on current val
    sat = map(val, valueMin, valueMax, satA, satB);  // Map sat based on current val
    
    for (int i = 0; i < NUM_LEDS; i++) 
    {
        leds[i] = CHSV(hue, sat, val);        
    
        // You can experiment with commenting out these dim8_video lines
        // to get a different sort of look.
        leds[i].r = dim8_video(leds[i].r);
        leds[i].g = dim8_video(leds[i].g);
        leds[i].b = dim8_video(leds[i].b);
    }
    
    FastLED.show();
    
} // end_main_loop

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.