LOOPING HELP!

Hello,

I need some help with some code and I think it may be simple but I just cannot find answers anywhere. The question is that i'm running a timer so that when you press a button it runs a piece of led code, however I want it to keep looping until I change to two button presses for a different flashing state. Hopefully you understand and can help.

Many Thanks

Jamie

So post what you have and say what it does and exactly what you want it to do.We help but tend not to do it for you.

Here is my code which you should be able to get what im trying to do:

int redPin = 11;
int greenPin = 10;
int bluePin = 9;
int buttonPin =2; // choose the input pin (for a pushbutton)
int val = 0; // variable for reading the pin status
int counter = 0;
int currentState = 0;
int previousState = 0;

void setup() {
  pinMode(redPin, OUTPUT);
  pinMode(greenPin, OUTPUT);
  pinMode(bluePin, OUTPUT);
  pinMode(buttonPin, INPUT); // declare pushbutton as input
  Serial.begin(9600);
}

void setColor(int red, int green, int blue)
{
  analogWrite(redPin, red);
  analogWrite(greenPin, green);
  analogWrite(bluePin, blue);  
}

void loop(){
  val = digitalRead(buttonPin); // read input value
   if (val == HIGH) { // check if the input is HIGH (button released)
     while
     setColor(255, 0, 255);  // green
     delay(1500);
     setColor(0, 255, 255);  // red
     delay(1500);
     setColor(255, 255, 0);  // blue
     delay(1500);
     currentState = 1;
}
else {
    setColor(255, 255, 255);  // green
    setColor(255, 255, 255);  // red
    setColor(255, 255, 255);  // blue
    
currentState = 0;
}
if(currentState != previousState){
if(currentState == 1){
counter = counter + 1;
Serial.println(counter);
  }
    setColor(255, 255, 255);  // green
    setColor(255, 255, 255);  // red
    setColor(255, 255, 255);  // blue
  }
previousState = currentState;
delay(250);}
if (val == HIGH) { // check if the input is HIGH (button released)
     while
     setColor(255, 0, 255);  // green

And that compiles?

oops sorry that was just something i was trying. the while was not meant to be there.

There are several styles regarding where to put the {. None of them allow for anything on the line after the }.

There is exactly one style for the }. It goes on a line ALL BY ITSELF.

There is a tool, under Tools + Auto Format that will straighten out that mess you posted. AFTER using that tool, AND verifying that the code will at least compile, post it again. Explain what it does that you don't want. Explain what it does not do that you do want.