RGB Led with two states problem.

Dear Arduino users,

I have ecnountered a problem with my project. I have an RGB LED connected to pins 2,3 and 4. I also have a push button connected to pin 8. I have 2 diffrent scripts, One for making it go Red Green and then Blue. And one for Mixing the collors by turning on all of them with a small delay between them. Now I though I wanted to have one script that had a button controlling which action it should do, circle through the colors or mixing them. So I found a buttonstatechanger script on the internet that didn't quite work for me. so I attempted to make ony myself which looks like this:

int Button = 8;         // the number of the input pin
int LED = 13;       // the number of the output pin
int state = HIGH;
int StateChange = 0;
boolean ButtonPressed = false;


      // the current state of the output pin
int reading;           // the current reading from the input pin
int previous = LOW;    // the previous reading from the input pin
boolean Mixing = false;

// the follow variables are long's because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long time = 0;         // the last time the output pin was toggled
long debounce = 200;   // the debounce time, increase if the output flickers

void setup()
{
  pinMode(Button, INPUT);
  Serial.begin(9600);
  Serial.println(StateChange);
}

void loop()
{
  TimeOutVoid();
  reading = digitalRead(Button);

  // if the input just went from LOW and HIGH and we've waited long enough
  // to ignore any noise on the circuit, toggle the output pin and remember
  // the time
  if (reading == HIGH && previous == LOW && StateChange == 0 || reading == HIGH && previous == LOW && StateChange == 2){
     Serial.println("StateChanged to 1");
     StateChange = 1;
     Serial.println(StateChange);
     TimeOut = 3;
     Serial.println(TimeOut);
     
   }
      
    if (reading == HIGH && previous == LOW && StateChange == 1 && TimeOut == 0){
     Serial.println("State Changed to 2");
     StateChange = 2;
     Serial.println(StateChange);
   }
   
   if (StateChange == 1){
    Do something here
   }
   if (StateChange == 2){
     Do something here.
   }
       previous = reading;

The script works absolutely fine, but here comes the problem. The button only seems to detect a push if you push it right at the end of either of the cycluses. So right after the Blue color when switching colors. Or right after the last mixed color. My guess is the arduino reads code from top to bottom. So it will only read the button press detection bit after the cyclus ended. I made two

My question is: Is there a way of making the void loop() and the voids that I setup for my two LED Modes, run at the same time so it will allways check for button pushes?

Thanks in advance,

Zenthor.

My question is: Is there a way of making the void loop() and the voids that I setup for my two LED Modes, run at the same time so it will allways check for button pushes?

No - the arduino is single threaded. This is a fairly frequently asked question. Your use of delay is the piece causing your issue and that traditionally means that you'll be advised to take a look at the blink without delay example that comes with the IDE.

  TimeOutVoid();

I got to here, and quit reading. C and C++ have functions, not voids.