Lightning effect with 3 leds

is that line not needed for the currently desired effect then?

No, the blink on the built in led is just to prove the machines alive: sometimes if it's in a long period with no lightning for example, you can tell at a glance it's not hung up.

So take that stuff out or // it, or of course add an external led on a pin of your choice and change the code to match.

your a star, your code takes up 87% of available memory allowing a little headway to add a digitalwrite HIGH command on another pin for some extra static lighting too.

your an absolute diamond!!

Once you're happy you follow how it works, // out all the serial print stuff, that will give some room back, and I always forget to use the F macro anyway, which I should do.

f macro? so i loaded it up onto a digispark board and wired up some resistors and leds to the relevant pins but seem to get no output

Explained here and in other places.

Can't help you there I'm afraid- I've never used an Attiny. All I can say is it worked for me on an Uno :wink:

Have you tried the good old blink sketch with the pin number changed so that you know the leds work on the 3 pins you have chosen? Got the leds the right way round?

all leds are good, loaded up a digital write high code i use to test all pin outputs

just for clarity, the polarity isnt reversed in your code is it?

i.e negative to the output pins instead of possitive?

Led anode to pin, led cathode to ground.

Do you have an Uno or similar to test on?

somewhere i will dig it out and see

so i tested it out on the auduino uno and works fine, but i cant get this to work in a digispark board.

heres whats been commented out and the full code being loaded.

// random lightning on 3 leds
// one "main" flash followed by two "secondary" flashes
//    includes blink-without-delay pulse on built-in led as proof-of-life
//    probably overkill but this code uses a state machine managed in a switch..case

//states
enum {state_new, state_main_flash, state_second_flash, state_third_flash} currentState = state_new;
bool justEnteredThisState = true;

unsigned long currentMillis;

unsigned long previousPulse;
int pulseInterval = 500;
bool pulseState;

//led array (use ~pwm pins to cater for brightness less than full)
byte ledPins[] = {3, 5, 6}; //index from 0 to 2 for 3 leds
const byte howManyLEDs = sizeof(ledPins) / sizeof(ledPins[0]);
int flashLengths[howManyLEDs];// will be populated each time, between the min and max
int flashLengthsMin[] = {100, 100, 100}; //experiment with these
int flashLengthsMax[] = {300, 300, 250};
int intervals[howManyLEDs]; // will be populated each time, between the min and max
int intervalsMin[] = {1000, 150, 300}; //between 3nd flash and new main flash, main and 2nd, 2nd and 3rd
int intervalsMax[] = {5000, 600, 1000};
byte secondFlashIntensity = 800; //experiment with these
byte thirdFlashIntensity = 300;
bool flashIsDone = false;

byte ledSequence[howManyLEDs]; //this gets populated later, in random sequence
unsigned long enteredThisStateAtMillis;
unsigned long flashEndedAtMillis;

void setup()
{
  //Serial.begin(9600);
  //Serial.println("https://forum.arduino.cc/t/lightning-effect-with-3-leds/1010662");
  //Serial.print("Compiler: ");
  //Serial.print(__VERSION__);
  //Serial.print(", Arduino IDE: ");
  //Serial.println(ARDUINO);
  //Serial.print("Created: ");
  //Serial.print(__TIME__);
  //Serial.print(", ");
  //Serial.println(__DATE__);
  //Serial.println(__FILE__);

  //pinMode(LED_BUILTIN, OUTPUT);

  //Serial.print("Initialising and testing ");
  //Serial.print(howManyLEDs);
  //Serial.print(" leds: ");
  //for (int i = 0; i < howManyLEDs; i++)
  //{
 //   pinMode(ledPins[i], OUTPUT);
 //   Serial.print(i);
//    Serial.print("/");
 //   Serial.print(ledPins[i]);
 //   Serial.print(", ");
 //   digitalWrite(ledPins[i], HIGH);
 //   delay(500);
 //   digitalWrite(ledPins[i], LOW);
  }
 // Serial.println(" ");
 // Serial.println("Leds initialised");
//  randomSeed(analogRead(0));
//  delay(1000);
//  Serial.print("setup() is done, starting.... "); Serial.println(millis());
//}//setup

void loop()
{
  currentMillis = millis();
//  pulse();
  doLightning();

}//loop

void doLightning()
{
  switch (currentState) //state_new, state_main_flash, state_second_flash, state_third_flash
  {
    case state_new:
      if (justEnteredThisState)
      {
        Serial.println("state_new");
        randomiseSequence();
        randomiseIntervals();
        randomiseFlashLengths();
        justEnteredThisState = false;
        enteredThisStateAtMillis = currentMillis;
      }

      if (currentMillis - enteredThisStateAtMillis >= intervals[0]) //interval from idle to 1st flash
      {
        currentState = state_main_flash;
        justEnteredThisState = true;
      }
      break;

    case state_main_flash:
      if (justEnteredThisState)
      {
        Serial.println("state_main_flash");
        enteredThisStateAtMillis = currentMillis;
        digitalWrite(ledPins[ledSequence[0]], HIGH); //main flash is always fully bright
        Serial.print("    main_flash ON "); Serial.println(currentMillis);
        //while (1) {} //temp stop for testing
        flashIsDone = false;
        justEnteredThisState = false;
      }

      //this is the flash:
      if (!flashIsDone && currentMillis - enteredThisStateAtMillis >= flashLengths[0])
      {
        flashIsDone = true;
        flashEndedAtMillis = currentMillis;
        digitalWrite(ledPins[ledSequence[0]], LOW);
        Serial.print("       main_flash OFF "); Serial.println(currentMillis);
      }

      //this is the inter-flash interval:
      if (flashIsDone && currentMillis - flashEndedAtMillis >= intervals[1])
      {
        currentState = state_second_flash;
        justEnteredThisState = true;
      }
      break;

    case state_second_flash:
      if (justEnteredThisState)
      {
        Serial.println(" state_second_flash");
        enteredThisStateAtMillis = currentMillis;
        analogWrite(ledPins[ledSequence[1]], secondFlashIntensity);
        Serial.print("    2nd_flash ON "); Serial.println(currentMillis);
        flashIsDone = false;
        justEnteredThisState = false;
      }

      //this is the flash:
      if (!flashIsDone && currentMillis - enteredThisStateAtMillis >= flashLengths[1])
      {
        flashIsDone = true;
        flashEndedAtMillis = currentMillis;
        digitalWrite(ledPins[ledSequence[1]], LOW);
        Serial.print("      2nd_flash OFF "); Serial.println(currentMillis);
      }

      //this is the inter-flash interval:
      if (flashIsDone && currentMillis - flashEndedAtMillis >= intervals[2])
      {
        currentState = state_third_flash;
        justEnteredThisState = true;
      }
      break;

    case state_third_flash:
      if (justEnteredThisState)
      {
        Serial.println("  state_third_flash ");
        enteredThisStateAtMillis = currentMillis;
        analogWrite(ledPins[ledSequence[2]], thirdFlashIntensity);
        Serial.print("    3rd_flash ON "); Serial.println(currentMillis);
        flashIsDone = false;
        justEnteredThisState = false;
      }

      //this is the flash:
      if (!flashIsDone && currentMillis - enteredThisStateAtMillis >= flashLengths[2])
      {
        flashIsDone = true;
        flashEndedAtMillis = currentMillis;
        digitalWrite(ledPins[ledSequence[2]], LOW);
        Serial.print("      3rd_flash OFF "); Serial.println(currentMillis);
      }
      
      if (flashIsDone)
      {
        currentState = state_new;
        justEnteredThisState = true;
        Serial.println("*** Heading back to the start... ***");
        //while (1) {} //temp stop for testing
      }
      break;
  }//switch
}//doLightning()

void randomiseSequence()
{
  Serial.print(" Sequence: ");
  ledSequence[0] = random(0, 3); //can be 0, 1 or 2
  Serial.print(ledSequence[0]);

  do
  {
    ledSequence[1] = random(0, 3);
  }
  while (ledSequence[1] == ledSequence[0]); //can't reuse
  Serial.print(ledSequence[1]);

  do
  {
    ledSequence[2] = random(0, 3);
  }
  while (ledSequence[2] == ledSequence[0] || ledSequence[2] == ledSequence[1]); //can't reuse

  Serial.println(ledSequence[2]);
  //while(1){} //temp stop for testing

}//randomiseSequence

void randomiseIntervals()
{
  intervals[0] = random(intervalsMin[0], intervalsMax[0]);
  Serial.print(" Main interval: "); Serial.println(intervals[0]);
  intervals[1] = random(intervalsMin[1], intervalsMax[1]);
  Serial.print("   2nd interval: "); Serial.println(intervals[1]);
  intervals[2] = random(intervalsMin[2], intervalsMax[2]);
  Serial.print("    3rd interval: "); Serial.println(intervals[2]);
  //while (1) {} //temp stop for testing
}//randomiseIntervals

void randomiseFlashLengths()
{
  flashLengths[0] = random(flashLengthsMin[0], flashLengthsMax[0]);
  Serial.print(" Main flash: "); Serial.println(flashLengths[0]);
  flashLengths[1] = random(flashLengthsMin[1], flashLengthsMax[1]);
  Serial.print("  2nd flash: "); Serial.println(flashLengths[1]);
  flashLengths[2] = random(flashLengthsMin[2], flashLengthsMax[2]);
  Serial.print("   3rd flash: "); Serial.println(flashLengths[2]);
  //while (1) {} //temp stop for testing
}//randomisFlashLengths

//void pulse()
//{
//  if (currentMillis - previousPulse >= pulseInterval)
//  {
 //   pulseState = !pulseState;
 ///   digitalWrite(LED_BUILTIN, pulseState);
//    previousPulse = currentMillis;
//  }

//}//pulse

also i did change the pin outputs to 0 1 and 4 for the digispark board.