Hi! I'm trying to make a LED brightness control using an arduino, and a nintendo nes controller, but instead of fading/increasing brightness, it will stay at one brightness. I think that the problem lies in the code. PLEASE HELP!! Here's the code: And yes I am new to arduino
int dn = 0;
int up = 0;
int bright = 0; // how bright the LED is
int fade = 1; // how many points to fade the LED by
const int dnbtn = 2;
const int upbtn = 3;
void setup() {
pinMode(9, OUTPUT);
pinMode(dnbtn, INPUT);
pinMode(upbtn, INPUT);
}
void loop() {
analogWrite(9, bright);
dn = digitalRead(dnbtn);
up = digitalRead(upbtn);
if (dn = HIGH)
{
if (bright > 0)
{
bright = bright - fade;
delay(1)
;}
else
{
}
}
else
{
}
if (up = HIGH)
{
if (bright < 255)
{
bright = bright + fade
;delay(1)
;}
else
{
}
}
}