Profile cover photo
Profile photo
Griff Malloy
5 followers
5 followers
About
Posts

Post has attachment
Add a comment...

Post has attachment
Add a comment...

Quick question on the technical side for anybody interested in helping with code

So with my current setup, I have the Arduino hooked up to the lights, and a push buttons as an input.
Apart from the setup and loop, I have three other functions. The first function rainbow() makes the strip of lights scroll through rainbow colors. The second function random() makes a random light turn on for .5 seconds, turn off, and then repeats itself. The final function is button() and uses a variation of this code https://www.arduino.cc/en/Tutorial/StateChangeDetection to work. As of now, this function only returns a value of true or false, where true lights up the whole strip and false turns it off.

I want to accomplish something simple, but I am not sure how to use nested functions to get this to work, as I have little experience with arduino and the C++ language.

What I want to do is have the button() function be a master command of sorts, where I can make the arduino switch between rainbow() or random() at the push of the button without delay. How would I go about using the button to select which function to run, where 1 push = rainbow(), 2 pushes = random(), n pushes = //functionname(), and after the last push the counter resets itself.

Something like this (not the real code obviously)
loop()
{
button()
{
if button == 1
rainbow()
if button == 2
random()
if button == etc...
functionname()
if button == total # of functions
button = 1
}
}

Thanks again for any help!

Post has attachment
Add a comment...

Post has attachment
Add a comment...

Post has attachment
Add a comment...

Post has attachment
Add a comment...

Hello to the FastLED community!

I am brand new with learning Arduino and I am teaching myself how to use the program as well as program my own light strip. Sorry if the following question is easy to answer, but I have been having trouble with arrays



So say I want the first 3 leds in my strip to turn on, but I do not want to write

leds[0].setRGB(255,0,0); FastLED.show();
leds[1].setRGB(255,0,0); FastLED.show();
leds[2].setRGB(255,0,0); FastLED.show();



So I tried to write the code like this instead

leds[0,1,2].setRGB(255,0,0); FastLED.show();
but only the third LED turns on



I have tried defining some leds into an array as follows

//writing variables
int start[3] = {0,1,2};
...
//run the setup
...
leds[start].setRGB(255,0,0); FastLED.show();



but I get the following error when verifying the code

"invalid types 'CRGB [450][int [3]]' for array subscript"



My question is, how can I make multiple LEDs turn on with one command, either through defining an array or by assigning them in the call to "leds[0,1,2,...]", without having to write "leds[0]...leds[1]...leds[2]..." multiple times?

Thanks again, sorry if there is an easy answer, but as I said, I am new to Arduino as well as this program

Post has attachment
Add a comment...

Post has attachment
Add a comment...
Wait while more posts are being loaded