How to interrupt a loop????

I need to constantly loop an array of LED’s and interrupt the loop (START/STOP) whenever I send a command through the serial port. *The code below I don’t have the input doing anything. This only loops the LED’s once then waits for an input. I want the LED’s to constantly loop and when it receives an ‘s’ to stop looping immediately, not to wait til the for loop is over. Any help would be great, I am new to this so please keep it simple.

int led = {22,23,24,25,26,27,28,29};
int input;

void setup() {
Serial.begin(9600);
for(int i = 0; i < 8; i++) pinMode(led*, OUTPUT);*
}
void loop() {

  • if (Serial.available() > 0) input = Serial.read();*
  • for(int i = 0; i < 8; i++){*
    _ digitalWrite(led*, HIGH);_
    _
    delay(100);_
    _ digitalWrite(led, LOW);
    delay(100);
    }
    }*_

check out

http://arduino.cc/en/Reference/Break

You'd get more replies to your question if this was in the programming section.

Use a boolean variable to control the LED flashy stuff. Check the serial input for your control commands, and set the boolean accordingly...

boolean doTheFlash = true;
char inputCmd;

void loop()
{

  if (Serial.available()) {

    inputCmd = Serial.read();

    switch (inputCmd) {
    case '0':
      doTheFlash = false;
      break;

    case '1':
      doTheFlash = true;
      break;
    }

  }

  if (doTheFlash) {

    digitalWrite...  etc

  }

}

You also need to use an index for your array in the pinMode and digitalWrite functions:

pinMode(led[i], OUTPUT);

That loop code does not wait for an input at all. Why do you think it does?

You also need to use an index for your array in the pinMode and digitalWrite functions

The OP did use an index for the array. But they didn't read the forum guidelines and use code tags. As a result, the [ i ] dissapeared and the rest of the sketch is in italics because that's what [ i ] means unless it is inside code tags.

Paul