Hello Everyone!
I'm stuck with a very simple code I presume, and I spent already a long time trying many things according to the arduino website.. something still wrong.
I hope I will fin some help and understand why I'm stuck!
Here the goal:
I have a normally closed switch (2) and a led (6)
The program wait till change of state switch opening
the led start Full
wait for a delay
and then fade out in XX seconds
everything works until the led is off then it turns on again, and fade.
So I'm stuck wuth my void loop and I try to make a second one but I don't know how.
Here the code:
const int buttonPin = 2; // the number of the switch pin
const int ledPin = 6; // the number of the LED pin
int brightness = 255;
int fadeAmount = 5; // how many points to fade the LED by
int buttonState = 0; // variable for reading the pushbutton status
void setup() {
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
pinMode(buttonPin, INPUT);
}
void loop() {
buttonState = digitalRead(buttonPin);
// check if the pushbutton is pressed. If it is, the buttonState is HIGH:
if (buttonState == HIGH) {
// do nothing
digitalWrite(ledPin, 0);
Serial.println("Wait");
}
else if (buttonState ==LOW)
{
Serial.println("Switch OFF");
analogWrite(ledPin, brightness);
delay(500); // delay led ON
for (int i=255; i>=0; i--);
{
brightness = brightness - fadeAmount;
Serial.println(brightness);
delay(50);
if (brightness <=0);
{analogWrite (ledPin, 0);
}
}
}
}
I hope my explanation is understandable, will someone take time to help me?
Thanks in advance,
MagicFlash