Led Brightness issue

int color = 2;         // blue=2, red=3, green=4, white=5
int outPin = 0;        // the number of the output pin

int state = HIGH;      // the current state of the output pin
int cinput;            // the current reading from the input pin
int pinput = LOW;      // the previous reading from the input pin

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(2, INPUT);
  pinMode(3, INPUT);
  pinMode(4, INPUT);
  pinMode(5, INPUT);
  pinMode(outPin, OUTPUT);

void loop()
  cinput = digitalRead(outPin);

  // if we just pressed the button (i.e. the input went from LOW to HIGH),
  // and we've waited long enough since the last press to ignore any noise...  
  if (cinput == HIGH && pinput == LOW && millis() - time > debounce) {
    // ... invert the output
    // ... and remember when the last button press was
    time = millis();    

  digitalWrite(outPin, state);

  pinput = cinput;
void changeled()
  digitalWrite(color, LOW);
  }else if(color==5){
  digitalWrite(color, HIGH);

I have a row of leds and this code switches which led is on when I press a button. It works fine in that respect but the leds are very dim. They are fine if i use the exact same wiring with the blink example program.

Which pins are the leds on ? and which pin is the button on? :-?

If pin 2,3,4 & 5 are used to pull one lead of the led to ground, then the pins should be outputs.

If you are using digitalread on outpin, then it should be an input but, it is also the serial RX pin so it may be wise to shift this to another pin.

There is also a digitalwrite to outpin as well ?

Edit. I have just seen that the leds are switched high, but the pins should still be outputs.

If all this is garbage, please ignore me, I am having trouble trying to make sense of it :)

lol im such an idiot. I had the led pins (2-5) as inputs and the switch pin 0 as output.

Also another question is there a way to control the voltage of the outputs.

You can't control the voltage of the ouputs, except to set them to 0V or 5V. But you can control the brightness of a LED, say, on certain digital pins by the techniqure of Pulse-Width Modulation (PWM):


It's a very popular topic, so have a look at this page from the Reference: