Different functions using 2 buttons I'm currently learning Arduino. So right now I'm trying to create an Arduino app that will use buttons, LEDs and RGB.

So I have 2 buttons, 8 LEDs and an RGB. The first button is the function switcher: when you press it the LED will light according to their function. The second button is the function activator so right now here's I want to do:


Function 1: Turn on/off RED light 
Function 2: Increase RED light brightness by 5; if already at 255, reset at 0 
Function 3: Turn on/off GREEN light 
Function 4: Increase GREEN light brightness by 5; if already at 255, reset at 0 
Function 5: Turn on/off BLUE light 
Function 6: Increase BLUE light brightness by 5; if already at 255, reset at 0 
Function 7: Turn on ALL lights, all brightness to 255 
Function 8: Turn off ALL lights, all brightness to 0 


I already started coding and I'm stuck at turning on and off the red light. Here's my code:

const int red = 5;

int b1, b2; //Buttons
int dir = 0;
int light = 11;
int func = 0;
boolean buttonValue = true;
boolean buttonState = true;

void setup() {
  pinMode(2, INPUT);
  pinMode(3, INPUT);
  pinMode(red, OUTPUT);
  for (int i = 11; i &lt;= 18; i++) {
    pinMode(i, OUTPUT);
  }
}

void loop() {
  b1 = digitalRead(2);
  if (b1 == HIGH) {
    dir = 2;
    func++;
    if (func &gt;= 8)
      func = 0;
    } else {
      dir = 0;
    }
    digitalWrite(light, LOW);
    if (dir == 2 &amp;&amp; light &lt; 18) {
      light++;
    }
    digitalWrite(light, HIGH);
    delay(200);
  }

void function(int pin) {
  b2 = digitalRead(3);
  switch (func) {
    case 1:
      if (b2 = true) {
        digitalWrite(5, HIGH);
      } else {
        digitalWrite(5, LOW);
      }
  }
}
I have to be honest after reading you description and looking at you code I have no idea how you arrived at the code you have arrived at.

For now lets try a much simpler bit of code, once that is working you can build on it.  

#define PIN_BUTTON_1    2
#define PIN_LED_RED     5

void setup() {
    pinMode(PIN_BUTTON_1, INPUT);
    pinMode(PIN_LED_RED, OUTPUT);
}

void loop() {
    const int buttonState1 = digitalRead(PIN_BUTTON_1);
    digitalWrite(PIN_LED_RED, buttonState1);
    delay(200);
}


If that code doesn't work then there is something wrong electrically.

I think is the next step you were trying for:

#define PIN_BUTTON_1    2
#define PIN_LED_RED     5

int lastButtonState1 = LOW;
int functionNumber = 0;
int currentLedValue = 0;

void setup() {
    pinMode(PIN_BUTTON_1, INPUT);
    pinMode(PIN_LED_RED, OUTPUT);

}

void loop() {
    const int currentButtonState1 = digitalRead(PIN_BUTTON_1);
    if (lastButtonState1 != currentButtonState1)
    {   // If the button's state has changed
        if (currentButtonState1 == HIGH)
        {
            ++functionNumber;
        }
        lastButtonState1 = currentButtonState1;
    }
    DoFunction(functionNumber);
    delay(200);
}

void DoFunction(const int&amp; function)
{
    switch (function)
    {
    case 1:
        if (currentLedValue &gt; 0)
        {
            currentLedValue = LOW;
        }
        else
        {
            currentLedValue = HIGH;
        }
        digitalWrite(PIN_LED_RED, currentLedValue);
        break;
    case 2:
        currentLedValue = 128;
        analogWrite(PIN_LED_RED, currentLedValue)
        break;
    default:
    }
}