Try removing the delay at the end of 'loop'. You can do this by 'commenting out' the delay line by putting // at the start of the line like this:
analogWrite(blueLEDPin, blue); // delay(10); }
This is a useful technique, because when you find out that you need to put the line back in again, you can do so, just by taking the // away again.
Without the delay, you will find that basically, whenever you release the button, you will be left with a random level of brightness for that color. What is happening is that the it is cycling through the brightness levels so fast, that you have no chance of actually controlling it.
Another experiment you could make would be to change the function of the three buttons so that they control the LED as if it was a traffic signal.
Try to make it so that the top button turns the LED fully green, the middle button Orange and the bottom button red.
Simon Monk is author of a number of books relating to Open Source Hardware. The following books written by Simon are available from Adafruit: Programming Arduino, 30 Arduino Projects for the Evil Genius and Programming the Raspberry Pi.
Page last edited October 11, 2012
Text editor powered by tinymce.