Arduino help -RGB LED

I am a coach for Shaker Robotics. I am in no way, shape, or form associated with our programming department. However, I have been trying to make a sign for a friend as a Christmas present. I have been running into problems with the programming, I have been poking around the Arduino forum without much luck and it just hit me that I should post on CD…I don’t know why I did not think about this before! :wink:

I could really use some help from someone who knows something about programming.

The Task: Mr friend is a member of the local Derby team. I want to make her a sign that uses 1 meter of RGB Flexable LEDs to make a fun and flashy sign. I want to use a push button to turn it on, select one of four programs (Fade through the rainbow, Fade between Orange and Pink, Strobe, and dim white) and then turn it off.

The Hardware: I am starting with this for the hardware…Thanks Adafruit

I am using the MOSFETs and it is wired up as show in the diagram. I have a pull-down push button switch connected to Digital IO 2.

What I have done: So I though that this would be relatively straight forward (famous last words!). I used the Change State Detection, and button examples from Arduino. I got the system to work great with a few very simple 1 LED programs (different rates of blink, constant on, etc.) In a completely different sketch I got all of the fades to work. I combined them together and PRESTO…nothing, the program get stuck in a loop at the Rainbow Fade and the Push Button won’t work anymore. So I post about it and one guy mentions that I need to use a State Variable code. I have researched it, and I have realized I am not anywhere near the level that I need to be to make this thing work.

This is my thread in the Arduino Forums. The “code” that I have written is posted there.

So the long and short of it, if you are looking for a challenge and would like to help a guy who is much more comfortable teaching Inventor and Machining I would appreciate it! It would make my present a lot cooler.

Well, I’m not much of a programmer either, but what happens, exactly, after you press the button once?

What I see is that you trigger the IF for 1 press. After you go through all those later IF statements for the various fades, then what happens? I think the program doesn’t know what to do after the first cycle of fades.

Also, when exactly is the button read in? Can the program get there again during normal runtime? If it can’t, then it can’t read the button any more and it will appear to be not working.

One thing that works for me is to manually walk through the code with paper to help keep track. It may take an hour, but bugs will be more obvious.

There are a few things in the last code block that you posted in that thread that are concerning.

  1. When you initialize your buttonState and lastButtonState varibales at the top, you set them to 0. You should use your LOW/HIGH constants. Depending on how those constants are defined, you could have trouble in your initial comparisons. (probably not causing your problem)

  2. I don’t see you setting lastbuttonState within your loop. (probably not causing your problem, but will be a problem once your current issue is resolved)

  3. You are missing a == in if(pushCounter = 4). That will always evaluates to true and always assign 0 to pushCounter (probably the cause of your problem)

A couple more things that I found that are going to give you problems.

You’re declaring ledState variables inside the pushCounter conditions within the loop. It looks like you’re intending to try to maintain that state between loops and this will not accomplish that. You’re already declaring a global ledState at the top, why are you redeclaring and reinitializing them again in the conditions?

The same goes for previousSlowMillis and previousFastMillis. They will always be 0 since you’re reinitializing them every loop.