RGB led and 2 pushbuttons


Im trying to light an led with two pushbuttons. I want it to work like this : If thereis no button pressed the blue led should be ON(only blue) if there is button 1 pressed red led should be ON(only red) if there is button 2 pressed green led should be ON(only green)

this is my code

int buttonPin1 = 2;  //button 1
int buttonPin2 = 3;  //button 2

int redPin = 11;   //red LED
int greenPin = 10;  //green LED
int bluePin = 9;  //blue LED

// setup starts serial communication and difines inputs and outputs
void setup()
  Serial.begin(9600); // serial start

  //defining inputs 
  pinMode(buttonPin1, INPUT);
  pinMode(buttonPin2, INPUT);

  //turning ON internall pull-ups

  //defining outputs
  pinMode(redPin, OUTPUT);
  pinMode(greenPin, OUTPUT);
  pinMode(bluePin, OUTPUT);


  loop watches for press on button 1 and button 2 and it turns on na RGBled
  no button press => blue LED
  only button 1 pressed => red LED
  only button 2 pressed => green LED

void loop()
  if (digitalRead(buttonPin1) == HIGH && digitalRead(buttonPin2) == HIGH)
    digitalWrite(bluePin, HIGH);
    digitalWrite(redPin, LOW);
    digitalWrite(greenPin, LOW);
  if (digitalRead(buttonPin1) == LOW)
    digitalWrite(greenPin, LOW);
    digitalWrite(bluePin, LOW);
    digitalWrite(redPin, HIGH);
  if (digitalRead(buttonPin2) == LOW)
    digitalWrite(bluePin, LOW );
    digitalWrite(redPin, LOW);
    digitalWrite(greenPin, HIGH);


but i can only switch between red and green leds and im stuck in the neverending loop(like arduino :P)

I would simply ditch the internal resistor pull-up, use external one (pull-down) and use reverse logic. LOW AND LOW for blue, HIGH LOW anf LOW HIGH for green or red.

Try this sketch with a slower refresh rate (2000).