Hello,
I've been trying to write a program which starts with led off (brightness = 0). It should wait until a button is pushed once (so the button state is not constant high), then it should fade in until the brightness is 255 and keep the brightness there.
When the brightness is 255 and the button is pushed again, it begins to fade out and stops when it reaches the zero.
My program just ignores the button altogether, fades in the led and that's about it.
I've studied Arduino books, different online tutorials and Jeremy Blum's tutorials, which have been the most informative, but I can't still get this thing work the way I want to. Debounce works with the same component layout.
Here's the code:
//Setup the Button
int buttonInt = 0; //digital pin 2
//Setup the LED
int faderLED = 11;
int brightness = 0;
void setup()
{
pinMode (faderLED, OUTPUT);
attachInterrupt(buttonInt, fadeIn, RISING);
}
void fadeIn()
{
if (brightness < 255)
brightness == brightness++;
delay(10);
}
void loop()
{
for (brightness = 0; brightness < 255; brightness++) {
analogWrite(faderLED, brightness);
delay(10);
}
for (brightness = 255; brightness > 0; brightness--) {
if (brightness < 255)
brightness == brightness++;
delay(10);
//Control LED Brightness
analogWrite(faderLED, brightness);
delay(10);
}
}
interrupt.ino (665 Bytes)