//* Flashing LEDs in a sequence *

#define MAX_LED (4) #define MAX_MODES (4) #define MAX_SEQU (3) // This variable needs to be declared in a .C file // as they are altered here and at the same time are used by the LED flushing function static uint8_t LED_mode[MAX_LED] = {0, 1, 0, 0}; /* modes (all at the same time period): 3 - continuously on 2 - long blinks 1 - short blinks 0 - continuously off */ // These variables can be declared within the LED-flashing function static uint8_t LED_phase[MAX_LED] = {0}; // which stage of a pattern is in progress (for the current LED) static uint8_t LED_counter[MAX_LED] = {0}; // pattern timing counter (for the current LED) // This constant look-up table can be declared within the LED-flashing function static const int16_t blinkdata[MAX_MODES][MAX_SEQU] = { { 0, 1000, -1 }, { 200, 800, -1 }, { 800, 200, -1 }, { 1000, 0, -1 } }; static const uint8_t LED_position[MAX_LED] = {1, 2, 4, 8}; if (LED_counter[i]==0) { ++LED_phase[i]; // advance to the next timing for the given sequence if (blinkdata[LED_mode[i]][LED_phase[i]]<0) LED_phase[i]=0; // but if we reached the sequence end then roll over to the beginning of the sequence while (blinkdata[LED_mode[i]][LED_phase[i]]==0) ++LED_phase[i]; // skip any "no time" phases if (blinkdata[LED_mode[i]][LED_phase[i]]<0) LED_phase[i]=0; // but if we reached the sequence end then roll over to the beginning of the sequence // note: actually there should be no "no time" stages at the end of a cycle LED_counter[i]=blinkdata[LED_mode[i]][LED_phase[i]]; // set up the amount of time until the next event // now service the event // check if the phase number is even or odd and switch on/off the LED if (LED_phase[i] &0x01) // checking if the phase is odd or even setLED( getLED() & ~LED_position[i] ); // LED off else setLED( getLED() | LED_position[i] ); // LED on } else { --LED_counter[i]; }