Hi, First of all I am new in Arduino, and a new project wanted to use it. The project requires a common LED to fade when a pushbutton is pressed. A code I found and modified a bit is this:
int brightness1;
int brightness2;
void setup() {
pinMode(5, OUTPUT); //LED
pinMode(6, OUTPUT); //LED
pinMode(12, INPUT_PULLUP); //button
pinMode(11, INPUT_PULLUP);
}
void loop() {
brightness1 = constrain(brightness1, 0, 255);
brightness2 = constrain(brightness2, 0, 255);
analogWrite(5, brightness1);
analogWrite(6, brightness2);
delay(10);
if (digitalRead(12) == LOW) {
(brightness1 = brightness1 + 1);
(brightness2 = brightness2 - 1);
}
if (digitalRead(11) == LOW) {
brightness1 = brightness1 - 1;
brightness2 = brightness2 + 1;
}
}
The problem is that when the pushbutton needs to be pressed too activate the loop. Is there a way to start the loop with just a push of a button?
Thanks