guys please help me out in verifying my program for my project -- led dimming effect using push button.
my project is simple ....i want to start the led fading effect with one click on the push button that means glowing and dimming effect one after the another and on my second click the led should turn off.
now the problem is coming in the programming part because this is my first own hand project and i'm beginner at arduino so i'm getting problem in doing the right programming for my project.
THIS IS MY SKETCH :-
int ledpin = 9;
int pushbutton = 8;
int brightness = 0;
int fadeamount = 51;
int buttonstate = LOW;
void setup ()
{
pinMode (ledpin,OUTPUT);
pinMode (pushbutton,INPUT);
}
void loop ()
{
if( digitalRead(pushbutton) == HIGH && butttonstate == LOW)
{
digitalWrite (buttonstate,HIGH);
analogWrite (ledpin,brightness);
brightness = brightness + fadeamount ;
delay (30);
if ( brightness = 0 || brightness = 255 )
{ fadeamount = -fadeamount ; }
}
else
{ buttonstate = digitalRead(pushbutton);
digitalWrite(ledpin,LOW);
}
}
plz suggest me changes in the program and the circuit diagram is given below in attachments.
