Dimming up and down

Hi all

I've been roped into programming some LEDs and im struggling with only my basic knowledge of c.
I want one button (pin2) to execute the dim up function, and one button to dim down. I can get one button to toggle up and down but i need a button for each.

Please excuse any mess and basic mistakes.

const int buttonPinU = 2; //GPIO Close contac goes beween ths and GND
const int buttonPinD = 4; //'' but for off
const int ledPin = 3; // Ch.1 on the RGB Board. (for ref. the RGB uses the following R=3 G=5 B=6)
const int fadingDelay = 50; //fade spd.
int buttonStateU = 0; // U BTN chk
int buttonStateD = 0; //''D
boolean fadingState = false; // State chk

void setup() {
pinMode(ledPin, OUTPUT);
pinMode(buttonPinU, INPUT);
pinMode (buttonPinD, INPUT);
}

void loop() {
// read btn value:
buttonStateU = digitalRead(buttonPinU);
buttonStateD = digitalRead(buttonPinD);

// check whether the btn was pressed
if (buttonStateU == HIGH) {
// chk LED status
if (fadingState == false) {
// turn on the LED
for (int i = 0; i <= 255; i += 3) {
analogWrite(ledPin, i);
delay(fadingDelay);
}
} {
if (buttonStateD == HIGH) {
// chk LED status
if (fadingState == false) {
// turn on the LED
for (int = 0; d <= 255; d -= 5) {
analogWrite(ledPin, d);
delay(fadingDelay); }

}
}
fadingState = !fadingState; // save the current LED state (on/off)
}
}}

Your Boolean "fadingState" is used for practically nothing.
at the end of loop() you toggle it.
during the loop you test it.
which only means that you fade up or down during one iteration but not the next, but again during the next, and so on.
maybe you had some practical use for it.

I think you have an error in your fade down for(..;..;..)
you should change fade down to

    if (buttonStateD == HIGH) {
    // chk LED status
    if (fadingState == false) {
      // turn on the LED
      for (int  = 255; d >= 0; d -= 5) { // <-- Start high and decrement down to 0
        analogWrite(ledPin, d);
        delay(fadingDelay); }
            
    
      }

You could make the structure of your program MUCH clearer by putting every { on a line BY ITSELF and putting every } on a line BY ITSELF and using Tools + Auto Format.

The reason that your switches don't work as you expect may be revealed when the code look more organized.

If not, it would be time to describe how the switches are actually wired.

I have two ptm buttons both coming from 5v to their respective pins then 2 pull down 10k resistors between gnd and each digital pin.

I've got the fade up to work but not the down as it looks like my code is wrong.

Dan95 yep I guess that Boolean is left over from when I had one button tagging the fade. It checked whether to fade up or down based on the led state I think

Thanks so much for the help ill try your amendment tomorrow.