Multitasking the Arduino for a newbie

Greetings,

There are 4 things that I would like to do simultaneously with the Arduino Mega.

  1. Use PWM to chase 12 LEDs in 2 arrays of 6, with fade in/out.
  2. Blink 6 LEDs on for 1 second every three seconds.
  3. Strobe 6 LEDs once every 2 seconds.
  4. Keep 12 LEDs lit.

This is for lighting a model of the Enterprise NX-01. Can anyone help me out with this? I learned how to make the PWM work one array of six, but no idea how to add the rest as code, or if it is even possible.

Here is a link to a video showing something similar to what I want to do.

Thanks

Here’s one way: You’ll need to setup some form of a state machine. Inside of your Loop(), add an incrementing variable. Then do checks against that variable to determine how many times you’ve gone around in the loop. From there, call different sub-routines for each of the functions you want. You’ll need to keep track of what state each of those functions are in, so you can make things flash the way you want.

http://www.arduino.cc/playground/Main/GeneralCodeLibrary#Timing_code

Metro and TimedAction will help multitasking. :slight_smile: