Arduino Operating System

Just loaded the last version I posted (the 992 byte compile) and I am right now watching led 13 give 3 quick blinks followed by 3 long blinks followed by 3 quick blinks, a long wait and repeat.

When I switch the sos pin to 2 and the uneven status blink on pin 13 and I get the status blink.
Please don't insult me with speculation that if I run both leds at once the timing of either changes. It won't at all.

I don't know what you loaded to your board or what you do but ---

Anyone on the forum with an Uno can see this for themselves. Here's the file to make an easy grab.

word  nowMs; // 16 bit millis is good to time 65.535 seconds

byte ledState, ledPin = 2; // use byte for small values, int cost 2 bytes
word startBlink, waitBlink[] = { 900, 100 };

void Blinker()  
{
  if ( nowMs - startBlink >= waitBlink[ ledState ] ) 
  {
    startBlink += waitBlink[ ledState ]; // next blink starts when it should, even if this one ended late.
    ledState = !ledState; // ! is logical NOT: 0 becomes 1, not 0 becomes 0. 0 is false.
    digitalWrite( ledPin, ledState ); // the led changes to the new state.
  }
}

// sos led vars
byte sosIdx, sosPin = 13;
const byte sosDo = 18;
word  sosStart;  // the sosTimes array could be putin PROGMEM and save 36 bytes of RAM
word  sosTimes[] = { 200, 250, 200, 250, 200, 500, 800, 250, 800, 250, 800, 500, 200, 250, 200, 250, 200, 2500 }; 

void SOS()
{
  if ( nowMs - sosStart >= sosTimes[ sosIdx ] ) // difference in time by subtracting start from end
  {
    sosStart += sosTimes[ sosIdx ]; // next blink starts when it should, even if this is late.
    digitalWrite( sosPin, sosIdx & 1 ); // the led changes to the new state.
    if ( ++sosIdx == sosDo )  sosIdx = 0;
  }
}

void setup()
{
  pinMode( ledPin, OUTPUT );
  pinMode( sosPin, OUTPUT );
}

void loop() // runs over and over 
{
  nowMs = word( millis());
  Blinker();
  SOS();
}[/quote]