Multiple Loops

So I'm starting a project that requires 4+ functions,

  • one pin toggles an LED strip showing a day cycle (sunrise to sunset),

  • one pin toggles a Relay on and off as the temperature changes

  • one pin toggles a relay on and off by the push of a button

  • one pin toggles the rotation of a servo

I have looked into a few things, like the Scheduler, but that does not work on a Mega2560 which I am using for my project. If there are any simple ways to toggle 4 different functions at the same time, please let me know.

Start here: http://forum.arduino.cc/index.php?topic=384198.0

Read all the stuff under General Design.

ChrisJorr:
I have looked into a few things, like the Scheduler, but that does not work on a Mega2560

God only knows what the Scheduler is but, if it works with Arduino at all, it wi ll work on a Mega2560. You are not looking for multiple loops, you are looking at multiple functions within the one loop, i.e. common practice.

Nick_Pyner:
God only knows what the Scheduler is but, if it works with Arduino at all, it wi ll work on a Mega2560. You are not looking for multiple loops, you are looking at multiple functions within the one loop, i.e. common practice.

Scheduler started out on the Arduino Due. It's rather specific to that platform so it doesn't work on the Mega. It is an official Arduino library. If you've never installed the Due extensions then you probably don't have it.

MorganS:
If you've never installed the Due extensions then you probably don't have it.

Ahem,, pardon me. You're right about that. I have never heard of it. I'm also surprised the Due is that different....

How "at the same time" do you need the switching to be? Down to the same clock cycle, or within a few milliseconds of one another?

Or do you just want four processes run in parallel, each doing their thing at their own time?

What kind of led strip? If it is an addressable one, you can have some fun in combination with the servo. This Adafruit article / library might be useful; no experience with it though.

Further you can have a look at Demonstration code for several things at the same time

ChrisJorr:
I have looked into a few things, like the Scheduler, but that does not work on a Mega2560

These links should get you started
Several Things at a Time
Planning and Implementing a Program

...R

If you prefer thinking of tasks, you can try the Task Macros.