Fade random red. Please

Hello,
Hunted for weeks as lost sketch, did find one on backup but not the sketch needing. Tried the online animators, but not same when run. This is as close as can find, but need to change to red, fade in out different positions. i would be most grateful, as no clue on coding...

#include "FastLED.h"
#define NUM_LEDS 30
CRGB leds[NUM_LEDS];
#define PIN 12

void setup()
{
  FastLED.addLeds<WS2811, PIN, GRB>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
}

void loop() {
  FadeInOut(0xff, 0xff, 0xff);
}

void FadeInOut(byte red, byte green, byte blue){
  float r, g, b;
     
  for(int k = 0; k < 255; k=k+1) {
    r = (k/255.0)*red;
    g = (k/255.0)*green;
    b = (k/255.0)*blue;
    setAll(r,g,b);
   
  }
     
  for(int k = 255; k >= 0; k=k-9) {
    r = (k/255.0)*red;
    g = (k/255.0)*green;
    b = (k/255.0)*blue;
    setAll(r,g,b);
    
  }
}

void showStrip() {
 #ifdef ADAFRUIT_NEOPIXEL_H
   // NeoPixel
   strip.show();
 #endif
 #ifndef ADAFRUIT_NEOPIXEL_H
   // FastLED
   FastLED.show();
 #endif
}

void setPixel(int Pixel, byte red, byte green, byte blue) {
 #ifdef ADAFRUIT_NEOPIXEL_H
   // NeoPixel
   strip.setPixelColor(Pixel, strip.Color(red, green, blue));
 #endif
 #ifndef ADAFRUIT_NEOPIXEL_H
   // FastLED
   leds[Pixel].r = red;
   leds[Pixel].g = green;
   leds[Pixel].b = blue;
 #endif
}

void setAll(byte red, byte green, byte blue) {
  for(int i = 0; i < NUM_LEDS; i++ ) {
    setPixel(i, red, green, blue);
  }
  showStrip();
}

type or paste code here

Is there a question hidden somewhere?

So you define float variables names but never give them a value.

Lots of similar misunderstandings.
The biggest one is that code is there to be found.

Then you either start to learn or you give up.

We are here to help you, but not to do it for you.

First off you need to learn to read code and understand the structure and syntax of the language.

I dont have yrs to learn, its just for 1 project. Added the sketch, just if some 1 good enough to modify.

Doesn't take years.

That's irrelevant.

What are you offering in return? We like to help people learn but we are not a free code writing service that you can just order up from.

I don't see that not happening:

The last line you quoted assigns to r, the others are similarly assigned.

To what variables do you refer?

@bjl1 I don't make any sense of

Also, this isn't like a telegram. There is no charge per letter or word, your writing style frustrates understanding.

If you have no idea how the sketch currently works, and you can't be more explicit about how it should, it will be hard to help.

If you are srsly in trouble, there's a a section where you could pay for what you seem to think should be free.

a7

OK I missed that, but these are not floating point values because not every calculation was a floating point value so it will be first done as an int and then assigned to be a float.

So is this some sort of homework or class assignment you have to do that you want some one to do for you?

Otherwise what is so important that you have no time to learn how to code?

The precursor.

1 Like

I saw this

r = (k/255.0)*red;

No matter what type k is, division by 255.0 yields a float. No matter what type red is, the multiplication will result in a float.

What am I still missing?

a7

The sketch has been here before, and works, but fades all thirty pixels.

First, remove this because you do not use Adafruit library.

void showStrip() {
#ifdef ADAFRUIT_NEOPIXEL_H
  // NeoPixel
  strip.show();
#endif
#ifndef ADAFRUIT_NEOPIXEL_H
  // FastLED
  FastLED.show();
#endif
}

void setPixel(int Pixel, byte red, byte green, byte blue) {
#ifdef ADAFRUIT_NEOPIXEL_H
  // NeoPixel
  strip.setPixelColor(Pixel, strip.Color(red, green, blue));
#endif
#ifndef ADAFRUIT_NEOPIXEL_H
  // FastLED
  leds[Pixel].r = red;
  leds[Pixel].g = green;
  leds[Pixel].b = blue;
#endif
}

... AND, remove this because you do not want all the LEDs to fade at one time...

void setAll(byte red, byte green, byte blue) {
  for (int i = 0; i < NUM_LEDS; i++ ) {
    setPixel(i, red, green, blue);
  }
  showStrip();
}

Which leaves you with this... but...

  • you want to delete two lines calling a function (see below)
  • add a line for a random value (see below)
  • and add two lines to fade-in and fade-out
#include "FastLED.h"
#define NUM_LEDS 30
CRGB leds[NUM_LEDS];
#define PIN 12

void setup() {
  FastLED.addLeds<WS2811, PIN, GRB>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
}

void loop() {
  FadeInOut(0xff, 0xff, 0xff);
}

void FadeInOut(byte red, byte green, byte blue) {
  float r, g, b;
  int ran = random(30); // <-- add this line

  for (int k = 0; k < 255; k = k + 1) {
    r = (k / 255.0) * red;
    g = (k / 255.0) * green;
    b = (k / 255.0) * blue;
    setAll(r, g, b); // <-- delete this line, you never use it
    leds[ran] = CRGB (r, g, b); // <-- add this line to fade-in a random pixel
    FastLED.show();    leds[ran] = CRGB (r, g, b); // <-- add this line
  }

  for (int k = 255; k >= 0; k = k - 9) {
    r = (k / 255.0) * red;
    g = (k / 255.0) * green;
    b = (k / 255.0) * blue;
    setAll(r, g, b); // <-- delete this line
    leds[ran] = CRGB (r, g, b); // <-- add this line to fade-out a random pixel
    FastLED.show(); // be sure to "show" the buffer
  }
}

WOW what a forum. Take people on face value, if you could only see what i came up with over the yrs, spending time researching, as a magician, things that have developed. If i or any 1 knows coding whats the point coming on here asking for help, Just wish you could see the props i have made in the magic world. Dont matter, have a mate at Uni who knows his coding, and willing to help, unfortunately not back in work till Wed. Forget i ever asked. Shocking

I've wanted to know magic my whole life. I've asked dozens of magicians at dozens of shows. I've never had one offer to set up a prop and teach me the trick for free. Every single one either said they'd never tell or they'd only show me for money.

Either way, why should we just jump up and create things for you just because you demand them?

LOL seriously, where was it i DEMANDED! 1 put up a sketch, asked for help to modify. Guess im in a different world here, as i go round those with learning difficulties, teaching these kids to adults simple magic, called magic for therapy. You get 12 people think worthless, in 4 mths, you get these to perform on stage in front of 200+ people for half hr. Out of good will, own free time and expense. As said whets the point in people on here if get slagged off like this, if we all know coding whats the point on forum. What a horrible forum. 1 will wait till Wed.. get a grip..

wat gives bruvva? I didn't pull my code bunny out of my ... hat.

We don't. The forum is here to help people that want to learn how. We help lots of those people to learn. We tried to help you to learn and you said that you didn't want to learn.

We're not a free code writing service.

The place isn't useless. You're just here for the wrong reason. We're not here to serve you.

If you want to learn a little then there is very little you need. But you'll have to get that from someone else. I'm muting the thread and won't see any responses you make.

Good luck.

?? where was it i said i dint want to learn? Obviously i want to learn, just the project i have done taken 9 mths for me to figure out on own, im just stuck on this part, to finish, have wife nagging me how long is the fire in the front room gonna be before finished. Over a month tried, from the online animations etc.

You said you don't have time to learn and asked for someone to just modify the sketch for you.

Are those not your words?

Am i illiterate here? "i dont have yrs", where does it stipulate "i dont want to learn". What the hell is wrong with you people. Come here politely asking if some one be good enough to modify a sketch for me, then get slandered. Gawd this forum been an eye opener, to the forums what im in help each other regardless. Dont ask for help here we dont do, go learn it.

Quit whinging and read post #10.

1 Like

Wasnt xfpd, seriously though the attitude of some people on here, shocking. Appreciate the help from you though. Figured out how to use the fastled online animator, now have exactly what needing.