// Multi_Blink.h//// Blink lots of LEDs at different frequencies simultaneously//// Header file is required to be able to define the structured types//#include <Arduino.h>

#ifndef MULTIBLINKH#define MULTIBLINKH

typedefstruct{uint8_t activeVal;// digital value for this state to be active (HIGH/LOW)uint16_t activeTime;// time to stay active in this state stay in milliseconds } stateDef;

typedefstruct{uint8_t ledPin;// Arduino I/O pin numberuint8_t currentState;// current active state
stateDef state[2];// the ON and OFF state definitions. Add more states if requireduint32_t lastTransTime;// the 'time' of the last state transition - saves the millis() value} ledTable;

#endif

// Multi_Blink//// Blink lots of LEDs at different frequencies simultaneously//// Marco Colli - May 2012//// Demonstrates the way to carry out multiple time based tasks without using the delay() function// Demonstrates the use of structures (and structures within structures)// Demonstrates a data driven approach to programming to create compact, reusable code//

void loop(){for(int i=0; i < MAX_LED; i++){// check if the state active time has expired (ie, it is less than current time)if(millis()>= T[i].lastTransTime+ T[i].state[T[i].currentState].activeTime){// switch to the next state with wrapround
T[i].currentState=(T[i].currentState+1)% MAX_STATE;

// write out the next state value
T[i].lastTransTime= millis();
digitalWrite(T[i].ledPin, T[i].state[T[i].currentState].activeVal);}}}