Multiple functions simultaneously?

Hi there,

first off I know the Arduino really isn’t capable of running multiple “functions” as such… but what I am trying to do is setup LED strip tail lights for my car, so it will have 4 strips in total (Left brake, Right brake, Left blinker and Right blinker) being controlled off 4 switches (Left blinker, Right blinker, Brake pedal and Tail light switch which would come on with headlights).
I have got the segments of code working in the right pattern as I want it but when the codes all as one it plays up… also when I release (turn off) the brake or tail light button/switch the blinker segment will play once… its really odd. I must add that I am more or less new to electronics and coding other then Expression2 from Garry’s Mod :o .
I’ve had to attach the code as it would not fit in the post, any and all help greatly appreciated!
Thanks :wink:

taillightcontroller4.ino (9.31 KB)

It sounds like Several things at the same time could be useful

UKHeliBob: It sounds like Several things at the same time could be useful

I've downloaded the example code and had a good read over it the other day but cant figure out how to utilize it for other functions..

first off I know the Arduino really isn't capable of running multiple "functions" as such.

That's nonsense. It can't run them simultaneously, but it CAN run any number of functions.

The key is to write them so that they do not block. Then, they can be run one after the other, and perform observable actions, like turning an LED on or off, close enough together to seem simultaneous by humans.

but cant figure out how to utilize it for other functions..

I have no idea how to help you, then. Robin2 has done an excellent job of documenting the process. If you can't adapt it to your needs, maybe computer programming is not a good career choice for you.

Maybe the slightly longer Planning and Implementing a Program will make the concept clearer.

In very simple terms your loop() code should be something like

void loop() {
    myFunctionA();
    myFunctionB();
    myF.....
    etc
}

...R

    for (BrakeL<=0; BrakeL <= CENTERTAILLIGHT; BrakeL=BrakeL+2)

Tell us about this for loop.

I'd also check whether it is legal in your country to tamper with the light controls in the way you are proposing.

AWOL:

    for (BrakeL<=0; BrakeL <= CENTERTAILLIGHT; BrakeL=BrakeL+2)

Tell us about this for loop.

Its so every second LED in the strip comes on, starting in the middle of the strip and going out toward each direction every second LED.

And the initialisation?

Edit: Hint: It's not just this for loop.

Yeah, it was clearly written and I made mostly sense from it just need to study the syntax a bit more I think. Thanks Robin2 for the tutorial and code, I will have to look further into implementing pre-defined functions. I have only been at this for little over a week and ultimately doing it for the tail lights in my car although it is proving to be a pretty interestingly fun after work hobby I won't be considering computer programming as a career choice. Thanks for all the helpful replies :)

AWOL:
And the initialisation?

Edit: Hint: It’s not just this for loop.

It’s inside

if(TailSw>1011&&BrakeSw<1011&&BlinkLSw<1011){}

Its messy code, I know.

No, I meant the loop variable initialisation (or lack of), here for (BrakeL<=0;

if(TailSw>1011&&BrakeSw<1011&&BlinkLSw<1011){}

Spaces don’t cost anything and make code much more readable

if (TailSw > 1011 && BrakeSw < 1011 && BlinkLSw < 1011){}

I take it that there is actually something inside the code block for the if test in the full program.