Hi there, I'm a complete newbie but am starting my first project to create

Hi there, I’m a complete newbie but am starting my first project to create a light bar. I have managed to successfully upload the fastled cylon to the arduino uno. I’m using ws2812’s, 1m strip of 30 leds.
The cylon needs to be able to change brightness and change speed preferable by analogue input (e.g.potentiometer), and also have different colour options. I’ve done alot of searching round online but not really been able to find answers to these difficulties so if anyone can point me in the right direction I’d be very grateful :slight_smile:

From the Cylon sketch, we know that the delay is shown as delay(30), which is a hard coded value. In order to change speed, this will have to be turned into a variable, so you can then write delay(speed). You will then want to define speed as an integer, connect a potentiometer to one of the analog ports, measure it in the loop and then assign the measured value to the speed variable. See ‘File | Examples | Analog | AnalogInput’ for reference.

You will want to experiment with the AnalogInput sketch to see the range of values returned before using it in your Cylong sketch.

Sounds like a fun project. Since analog read returns a value in the range of 0-1023, and FastLED uses 0-255 for its brightness range, you might find the map function to be useful.
http://arduino.cc/en/reference/map

Thanks for those responses, I understand the map function and the delay thing better now but am still struggling to get it to work. I’ll persevere and keep you posted. Many thanks :slight_smile:

And for the colour of the LED’s, rather than use:

leds[i] = CRGB::Red;

try:

leds[i] = CHSV(hue, 255, 255);

where ‘hue’ is a mapped value from another joystick that ranges between 0 and 255.

Believe me, perseverance and Google-fu are the keys to getting these projects running.

I’m a noob also but here some hints i can give you based on my experience. Find examples if you don’t know how to code. For example find potentiometer example and copy and paste the code into your cyclone example. Just remember to put the correct parts in the correct places like the setup, void loop, ect.

@Veronica_Willis I’ve just hacked up the cylon example to add speed and brightness.You may need to fiddle with the values, but it should be enough for you to get going.
I’ve tried to keep it verbose, and use I’ve used two arduino functions:
map() and constrain()

I’ve done this as you will find these in lots of arduino projects, and so it should be easy for you to understand, but shout if you get lost.

Once you know how its working, we can simplify, the code, by making it less verbose. But, baby steps.

I hope this helps.

and now with colour as per @Andrew_Tuline suggestion :wink:

Thanks so much Stuart Taylor, I really appreciate this. So far I have uploaded your first version which worked perfectly. I did get a couple of compiling errors which I’ll write here just in case anyone else wants to use this code in the future; line 66
outputValue = constrain(mappedValue, MIN_BRIGHTNESS, MAX_BRIGHTNESS);

returned an error " :outputValue’ was not declared in this scope"
so I typed
outputValue = 0 within the declarations at the top,

and line 69 was missing a semi-colon. (I was quite pleased with 3 weeks experience to be able to fix those and make it work!!)

I can follow the code and it makes sense but I certainly don’t have the experience to write that (yet!).

I am assuming that if I want to change the scope of the speed I can just change the last 2 values in this line ?
int delayValue = map(speedValue, 0, 1023, 10, 300);

I am waiting for some more pots to arrive and will hopefully load up the colour version at the weekend :slight_smile:
Thanks so much, and I will let you know how the rest of it goes.

Hi,

sorry about the typos, i didn’t actually run any of the code, and i ordered some pots to validate it, but they haven’t arrived yet. I’m glad you were able to fix it, well done!

You are correct. The line you have for speed, is mapping the analogue value read from the pot, which will go from 0 to 1023, onto an arbitrary range i set 10 to 300.

So increasing the value from 300 will increase the range over the pot, and the effect it will have, will be to slow it down more. Likewise change the value 10 to 0, would speed it up by 10ms.

eg

int delayValue = map(speedValue, 0, 1023, 0, 9000);

Have a play with the values. You may find that you need to set an upper and lower value.

Good luck, and let us know how you get on.

So my pots arrive this morning, and i’ve had a quick play.

i found these values worked well

int delayValue = map(speedValue, 0, 1023, 0, 50);

i’ve updated the example code (with fixed typos, thank you) using those values.

And while i was at it, i have refactored the code slightly so we don’t read things into variables (int) then use those variables in another function, instead we just get the function to read the value directly, and so we save a little bit of precious RAM, but i left the original code in, i’ve just commented it out, so it wont be too different for you to read, and it should allow you to work out how i’ve changed it and what’s happening.

Now i’ve had a play with the code, there was an obvious flaw in it. Once the animation was running, if you changed the colour control, your change wouldn’t be reflected until there had been one full sweep (back and forth) of the LEDs.

I have moved the reading of the value, to inside the loops that control the LEDs position in the effect, and now the colour appears to be changed as you change the value of the pot, which is what we would expect.

the updated code is here:

Brilliant! I have had a play too (not with the new code yet) and I like how it works so far. I had a play with the delay values so I’m really happy with how that works. The animation needs to be followed by the eye so I’ve narrowed it down to between 10 and 80.
I was thinking about whether I could put the sensor readings inside the loops so that answers that question, thank you.

The last part I’m trying to figure out is to have a button (I’ve ordered momentary buttons) to start the animation and then to stop it, however, because the animation is designed to have someone follow it with their eyes I’d like it to do 2 or 3 sweeps and then stop in the middle with decreasing speed on each sweep or part sweep. I haven’t written in the button yet although that should be ok, but I’m working on what I want to happen on the “off” signal. I’ve managed to make it sweep twice and stop in the middle. What I’ve tried to do at the end is get it to stay on for 3 seconds and then switch off. As i’m hijacking bits from tutorials and forums it probably looks very awkward (and maybe a bit long winded) but any hints on getting this to work would be greatly appreciated :slight_smile:
Here is the code as a stand-alone:

Hi, thats an interesting project.

I uploaded a short video of the 3 pots working, on the updated code (reading pots inside loops). The leds are quite dim in the ideo because they were running off the USB port 0_o

When adding a button, you can trigger an event on:

just pressed
just released
still pressed (a long press)

So you will be able to achieve what you want.

Don’t forget to take some photos/video and #showoffyourwork

I’ve already realised a fundamental flaw… I don’t want the loop to stop completely at the end of the code but to wait for a signal from the button to start again…
re-thinking!

A momentary push button can be made to toggle in software. I.e push to start, push again to stop.
I don’t know what type of arduino you are using but its easy to have multiple buttons, each with its own function, and each can have a different style of operation.