Page 1 of 1

FastLEDs fun with a broken switch/case

FastLEDs fun with a broken switch/case

Welcome to the Tweaking4All community forums!
When participating, please keep the Forum Rules in mind!

Topics for particular software or systems: Start your topic link with the name of the application or system.
Examples: "MacOS X - Your question", "MS Word - Your Tip or Trick".

Please note that switching to another language when reading a post will not work!
Posts will not have a translated counterpart.

RSS Feed

Home Forums Hardware Arduino FastLEDs fun with a broken switch/case

This topic contains 8 replies, has 2 voices, and was last updated by  hans 2 years, 7 months ago.

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
  • 7490


    Hi Hans,

    I posted on the effects article saying I would create a topic but there was something wrong, I couldn’t. So I answered my post and probably trigger an anti-bot detection which got rid of all the explanations I had written…  Let’s do it again!  

    I am currently working on DAC design since last year. In the first place I wanted to use basic LEDs with PWM to modify their brightness in VHDL. Unfortunately for me I suck a lot at VHDL and during my struggle with it I came across your website and more precisely FastLEDs effects article… Bookmarked! I believe this helps a lot of people getting started with these and the time and patience you took to right it makes it all very educational!

    Now back to the subject of interest. I want to cycle through phases:
    1st phase: I used fade in/out effect to light up from 0% to 100% (I actually don’t use 100% because it’s making too much light) and then back to 0%. I replaced the ramp with a sine waveform. For those who wonders how, here is my source and the reason why I used radians.
    2nd phase: I used twinkle effect to indicate that the RaspberryPi is starting and then connects to my NAS server
    3rd phase: Once connection is established, the RaspberryPi update an output to inform the Arduino that the connection is OK. From there I want to animate another time with the sine waveform fade in/out again except this time it wont go down to 0% but instead a ‘brightness’ value.
    4th phase: Here I used a fade in/out without the loop to keep the same brightness all the time.

    All seemed goos to me but I have a weird behaviour if I run the program. Phase 1 &2 works perfectly fine, no glitch whatsoever. Then when I connect the ‘RaspberryPi Connected’ wire it breaks my switch/case and each case seems to be running at the same time…  I could make a video if required 

    I wanted to debug using the serial console connection but since I actually don’t use an Arduino but rather an Adafruit Pro Trinket and it doesn’t have the serial-to-USB chip… I’m stuck with only my eyes, fingers and what’s left of my neurones and it doesn’t seems to be enough  Although I’m a beginner with Arduino sketches so I might miss something quite easy. I attached two files, one has setup and loop and the other have the functions called.

    Any help is very much welcome 



    I updated the code with different style of animations while waiting for connection to the NAS server. See attached code.
    It made me realize what seems to be happening is that sometimes (I don’t know why) but I have the bug I described in my previous post. Except this time it happens with the theater chase effect (phase 2) and it executes sequentially phase 1 and phase 2. all other animations works nicely.
    Problem also appears in phase 3 and seems to do phase 1 and 2 mixed. Very weird! 




    I updated the code to use if statements instead of switch/case.
    It seems a bit better to me but there still are glitches when executing phase 3. It doesn’t seems to ever go in phase 4 and phase 1, 2 and 3 seems parasitising each other but I just seems to not be able to figure this out.  



    Hi Cam,

    sorry for the late response – thing have been a little crazy here the past few days … (still looking for a rich sponsor who wants to pay me to do this website as a day time job hahah )

    First off, since it confuses me… what do you mean with DAC?
    In my world that would be a Digital Analog Converter, but I’m sure that not what you mean .

    I’ve looked at your code, and theoretically they look fine. I did like the first approach, using the switch statement, the best.
    But one thing that might interfere and that would be the time it takes to run an effect.

    What I usually do when I get stuck like this: start over and eliminate everything – just stick with the basic structure.

    So we have 4 phases:

    1: Start with Effect1 (fade in/out) when Arduino starts
    2: Use Effect2 (twinkle) when RPI starts
    3: Use Effect3 (slightly different fade in/out) when RPi successfully connected to NAS
    4: Effect4 (fade in/out) after 1, 2, and 3 have completed

    Did I get that right? Sorry if I’m not quite getting it – I need more coffee hahah 

    So basically we’d like the effects to match the status of your RPI.
    I know I might be misunderstanding what you’re trying to do …. in my head, early in the morning … it looks like this:

    1) RPI (connected to Arduino) is powered on but still booting – Effect 1
    2) RPI is ON and getting ready to connect to your NAS – Effect 2
    3) RPI is connected to the NAS – Effect 3
    4) RPI is 100% up and running – Effect 4

    Are you using a switch in the Arduino to power on the RPI? Or do you rely on the same power supply?



    Hi Hans,

    Don’t worry about the time it takes to get an answer as long as I do get it right  We do live on the same world! I meant DAC as you think of it and I’m glad that for once I don’t get the question “what is a DAC?” when I talk about my project. It was irrelevant to talk about it but I wanted to put some context. Right now the context is that I stuck with parts since I’m waiting for my mouser order to make the PSU. I attached a picture of the current status of the project for a better context and the 10 LEDs are supposed to be on a board around the hole where the switch is going to go. The idea is to have a circle of light around the power switch (which is round with a diameter of 4cm) to get user feedback of the current status of the DAC (ready to play music or not). It’s always easy to forget to mention some stuff that I think is obvious so is that a better context?

    To me, the code looks good too that’s why I wondered if there may be something I don’t know about Arduinos usage since I’m new to this. I don’t think the time it takes for an animation matters because we change from phase 2 to phase 3 (where problems appears) according to the inputs and not the cycle (phase 1 and 3 where they only execute the animation once).

    You definitely got the sequence right (I know coffee helps a lot sometimes), just as a precision, phase 4 is only steady lighting and stays that way all time except if there is loss of connection with the NAS server (where the music is located). If such thing happened then it would go back to phase 2. Phase 1: DAC turned on, phase2: DAC(RPI) looks for the server and connects to it, phase 3: animation to indicate the DAC is connected to server and then phase 4: steady lighting while ready to play (either IDLE or playing music).

    Interesting idea about power supplies. Normally I would test with the PSU that will go in it but unfortunately for now it is not possible (waiting for parts) so, during my tests, the Arduino is powered by its USB cable connected to my laptop and the 10 LEDs strip are powered by a bench PSU. I’ll try right now to connect grounds from laptop and PSU to see if it’s better. I’ll also try to look at the phase 3 animation code since it’s weird to have issues on phase 3 only with both switch/case and if statements.



    AND there it is fixed! 
    I would not say that you found the issue but you definitely put me into this direction, probably the coffee mug helped focus as well. Power supplies issue made me look back into the wiring > added connection between grounds > replace my ‘connectedRPI’ test cable because it was loose on the Arduino pin > checked again pins layout on Arduino (mine is a Adafruit pro trinket without serial console chip) > FOUND OUT I changed for weird reasons input pin from 3 to 2 during my desperate tries and you know what? There are no pin 2 on pro trinkets.
    For sure, grounds needs to be connected otherwise it flickers weirdly. Still I think I’ll buy a real Arduino with serial console so I can test everything on it, it is not like it costs a thousand euros.
    Thanks Hans for the help, I’ll now modify a bit again the animation to get them as smooth as possible using sine waveforms. I’ll post the modifications and probably I’ll make a video when the parts get here just put even more context to the topic 
    I’m happy!

    Without your article, this would never have happened, Thank you very much for that 


    Thanks Cam!
    And … Awesome to hear that you found it! 




    Actually I have a bit more precisions on what was not working. I had multiple problems, I admit it The fact that It seemed to have all animations at the same time was because I forgot to put breaks at the end of cases 2 &3 (for steps variable). It is also why the for statements worked a bit better than the switch/case.It is strange but if there is no break, the switch will continue with the next value even if the variable in the switch does not move a finger. That’s good to know!
    2nd problem was that I did not connect grounds of LEDs and Arduino. If you do not do this, it might works ok but it doesn’t hurt to join both grounds (Do not connect both 5V!).If not connected, LEDs might flicker a bit or it could flicker a lot.
    I believe that was all, hope it will help a few 



    Well, don’t feel bad … I tend to forget the “break;” when using the “switch” statement quite often as well – which causes some interesting effects at time and can be a pain to fix hahah … 

Viewing 9 posts - 1 through 9 (of 9 total)

You must be logged in to reply to this topic.