Loops for individual timers?

Hi All
I'm trying to write separate loops to run on each timer if I can to activate muscle wires via ultrasound
I'm using a mega2560 r3, I think I'm right that it has 6 internal timers, perhaps even 3 channels on each that can be used
I'm more aware that you can't really multi task on arduino, am trying to make a sketch that runs an ultrasound sensor loop that triggers various movement actions or functions to activate the muscle wire which pulls flowers to 'sway' for a project for someone

Have tried some example libraries that have 3 separate loops pre written but it still hangs on the first task you give it then does the others after. Duinos looks like where I should be headed, have some experience with adding libraries etc, need a good syntax reference for it

Can I just write a loop for each timer on the mega and get them to talk to each other via global variables?

Or any useful advice or links would be greatly appreciated!

Many thanks
Dominic

Does the blink without delay example provided with the IDE give you any clues?

Hi thanks for reply
I've been looking at using for loops or the milli tutorial and it makes sense, it's seems a bit complicated when I try to imagine what I'm trying to do, I need to just keep reading through and trying to make it a bit more complex at a time

(the project is a bunch of flowers that move via muscle wire, as you walk near them it picks you up with ultra sound and triggers different movements of the flowers from a bunch or pre written movement funcitons (ideally, or somehting like that), ie slowly, quickly, pwm to make it move differently, wobble, etc or a library of movements/functions and it picks a random number and triggers one of the movements, doing this simultaneously for up to 8x flowers without pausing while it moves one flower then onto the next so it has a random and more natural feel to it. or any method that does the same, this is at the edge of my programming knowledge)

I thought logically it might be easier if you could have one loop running the ultrasound trig/echo loop and updating a global variable with the distance it reads

Another loop running if or switch on the distance reading and selecting movement patterns

then either a loop for each flower that gets sent stuff from another variable or function , random sequence generator, or something to that effect. or a loop that runs all the flowers and steps through sequences when each flower is sent a trigger of some sort from the ultrasound reading

I was hoping I could do that with duinos? but I can't seem to find much documentation yet, i tried the other day but the guide is for ide021 or something and the folders aren't the same on 1.02 so am not sure if I got that wrong, or I was going to try the milli / interrupts thing and try to think out a way to do all that

it's a syntax problem or programming really I know pretty much the kinds of things you could do but not how to string it together in that way, understand is complicated and am not expecting a sketch from someone, sounds like that's some good feedback though, my nest bet is to concentrate on the milli example of flashing two led's and go from there?

Many thanks again
Dominic

I'd look at the blink without delay example and play around with it.
First step, one LED, but with different on and off times.
Then two LEDs at different frequencies, then different on/off times, then maybe one going continuously, and the other only when triggered by a switch.
You should end up with sketches no more than about thirty or forty lines long.

dominiclane:
I thought logically it might be easier if you could have one loop running the ultrasound trig/echo loop and updating a global variable with the distance it reads

Another loop running if or switch on the distance reading and selecting movement patterns

then either a loop for each flower that gets sent stuff from another variable or function , random sequence generator, or something to that effect. or a loop that runs all the flowers and steps through sequences when each flower is sent a trigger of some sort from the ultrasound reading

That sounds like the right sort of idea, but instead of thinking of these as separate loops, think of them as separate pieces of code that are called within the loop() function so that they execute repeatedly. Each piece of code would use the approach demonstrated in 'blink without delay' to determine whether it was time to do something, and do it when necessary. This approach will enable you to do the ultrasound sensing and move the flowers concurrently.