[SOLVED] How to declare multi inheritance class file header

Hi, I'm trying to export my class "ButtonPedal" from main .ino file to a header .h and c++ .cpp files but I have the error :
"expected class-name before ',' token"

My class "ButtonPedal" works fine in the main file .ino

This is the original class minimal code in the main sketch:

class ButtonPedal : public Button, public Led {
  private:
    byte programChange;

  public:
    ButtonPedal (int _pinButton) : Button (_pinButton), Led(_pinLed) {
      programChange = _programChange;
    }

    void update() {
      if (Button::isPressed()) {
        midiOut.sendProgramChange(programChange, midiChannel);
      } // fine if isPressed
    } // fine update

};

then I tried to export this class to classic two files .cpp and .h
but in the header file at line <class ButtonPedal : public Button, public Led {>
I have this error:
"error: expected class-name before ',' token"

ButtonPedal.h minimal code:

#ifndef BUTTON_PEDAL_H
#define BUTTON_PEDAL_H

#include <Arduino.h>

class ButtonPedal : public Button, public Led {
  private:
    byte programChange;

  public:
    ButtonPedal (int _pinButton, int _programChange) : Button (_pinButton), Led(_pinLed);
      void update();
  };
#endif

ButtonPedal.cpp minimal code:

#include "ButtonPedal.h"

class ButtonPedal : public Button, public Led {
    ButtonPedal::ButtonPedal (int _pinButton, int _programChange) : Button (_pinButton), Led(_pinLed) {
      programChange = _programChange;
    }

    void ButtonPedal::update() {
      if (Button::isPressed()) {
        midiOut.sendProgramChange(programChange);
      } // fine if isPressed
    }  // fine update

};

I thank You in advance for any help.
Regards
Dennis

I don't see definitions for your Button and Led classes.

Shure, this is the code for:
<Button.h>

#ifndef MY_BUTTON_H
#define MY_BUTTON_H

#include <Arduino.h>

class Button {
  
  private:
    byte pin;
    byte state;
    byte lastReading;
    unsigned long lastDebounceTime = 0;
    int debounceDelay = 50;
    
  public:
    Button(byte pin);

    void init();
    void update();

    byte getState();
    bool isPressed();
};

#endif

<Button.cpp>

#include "Button.h"

Button::Button(byte _pin) {
  pin = _pin;
  lastReading = HIGH;
  init();
}

void Button::init() {
  pinMode(pin,OUTPUT);
  digitalWrite(pin,LOW);
  pinMode(pin, INPUT_PULLUP);
}

void Button::update() {
    byte newReading = digitalRead(pin);
    
    if (newReading != lastReading) {
      lastDebounceTime = millis();
    }

    if (millis() - lastDebounceTime > debounceDelay) {
      state = newReading;
    }

    lastReading = newReading;
}

byte Button::getState() {
  update();
  return state;
}

bool Button::isPressed() {
  return (getState() == LOW);
}

<Led.h>

#ifndef MY_LED_H
#define MY_LED_H

#include <Arduino.h>

class Led {

  private:
    byte pin;
    boolean ledAnalog;
    byte lumen;
    byte lightSelected;
    
  public:
    byte tempLightOff;
    byte lightOff;
    byte lightOn;
    byte fadeStep;
    Led(byte pin, boolean analog = false);
    void selected();
    void init();
    void on();
    void off();
    void setLightOn(int val);
    void setLightSelected(int val);
    void setLightOff(int val);
    void setSelected();
    void deselect();
};

#endif

<Led.cpp>

#include "Led.h"

Led::Led(byte _pin, boolean _analog = false) {
  pin = _pin;
  ledAnalog = _analog;
  init();
}

void Led::init() {
  pinMode(pin, OUTPUT);
  lightOn = 255;
  lightSelected = 80;
  lightOff = 3.0;
  tempLightOff = lightOff;
  fadeStep = 1;
  lumen = lightOff;
  off();
}

void Led::on() {
  if (ledAnalog) {
    lumen = lightOn;
    analogWrite(pin, lumen);
    Serial.println("lumen:" + String(lumen));
  } else {
    digitalWrite(pin, HIGH);
  }
}

void Led::off() {
  if (ledAnalog) {
    lumen -= fadeStep;
    if (lumen <= tempLightOff) {
      lumen = tempLightOff;
    }
    analogWrite(pin, int(lumen));
    delayMicroseconds(1000);
  } else {
    digitalWrite(pin, LOW);
  }
}

void Led::setSelected() {
  tempLightOff = lightSelected;
}

void Led::deselect() {
  tempLightOff = lightOff;
}

void Led::setLightOn(int val) {
  lightOn = byte(constrain(val, 0, 255));
}

void Led::setLightOff(int val) {
  lightOff = byte(constrain(val, 0, 255));
}

ButtonPedal.h needs to #include Button.h and Led.h.

Very Thank You for correction !!! I have updated the classes files with Your correction and some other bugs...

<ButtonPedal.h>

#ifndef BUTTON_PEDAL_H
#define BUTTON_PEDAL_H

#include <Arduino.h>
#include "Button.h"
#include "Led.h"

class ButtonPedal : public Button, public Led {
  private:
    byte programChange;

  public:
    ButtonPedal (int _pinButton, int _pinLed, int _programChange) : Button (_pinButton), Led(_pinLed) {};
    void update();
};
#endif

<ButtonPedal.cpp>

#include "ButtonPedal.h"

class ButtonPedal : public Button, public Led {
    ButtonPedal::ButtonPedal (int _pinButton, int _pinLed, int _programChange) : Button (_pinButton), Led(_pinLed) {
      programChange = _programChange;
    }

    void ButtonPedal::update() {
      if (Button::isPressed()) {
        midiOut.sendProgramChange(programChange);
      } // fine if isPressed
    }  // fine update

};

<Button.h>

#ifndef MY_BUTTON_H
#define MY_BUTTON_H

#include <Arduino.h>

class Button {
 
  private:
    byte pin;
    byte state;
    byte lastReading;
    unsigned long lastDebounceTime = 0;
    int debounceDelay = 50;
   
  public:
    Button(byte pin);

    void init();
    void update();

    byte getState();
    bool isPressed();
};

#endif

<Button.cpp>

#include "Button.h"

Button::Button(byte _pin) {
  pin = _pin;
  lastReading = HIGH;
  init();
}

void Button::init() {
  pinMode(pin,OUTPUT);
  digitalWrite(pin,LOW);
  pinMode(pin, INPUT_PULLUP);
}

void Button::update() {
    byte newReading = digitalRead(pin);
   
    if (newReading != lastReading) {
      lastDebounceTime = millis();
    }

    if (millis() - lastDebounceTime > debounceDelay) {
      state = newReading;
    }

    lastReading = newReading;
}

byte Button::getState() {
  update();
  return state;
}

bool Button::isPressed() {
  return (getState() == LOW);
}

<Led.h>

#ifndef MY_LED_H
#define MY_LED_H

#include <Arduino.h>

class Led {

  private:
    byte pin;
    boolean ledAnalog;
    byte lumen;
    byte lightSelected;
   
  public:
    byte tempLightOff;
    byte lightOff;
    byte lightOn;
    byte fadeStep;
    Led(byte pin, boolean analog = false);
    void selected();
    void init();
    void on();
    void off();
    void setLightOn(int val);
    void setLightSelected(int val);
    void setLightOff(int val);
    void setSelected();
    void deselect();
};

#endif

<Led.cpp>

#include "Led.h"

Led::Led(byte _pin, boolean _analog = false) {
  pin = _pin;
  ledAnalog = _analog;
  init();
}

void Led::init() {
  pinMode(pin, OUTPUT);
  lightOn = 255;
  lightSelected = 80;
  lightOff = 3.0;
  tempLightOff = lightOff;
  fadeStep = 1;
  lumen = lightOff;
  off();
}

void Led::on() {
  if (ledAnalog) {
    lumen = lightOn;
    analogWrite(pin, lumen);
    Serial.println("lumen:" + String(lumen));
  } else {
    digitalWrite(pin, HIGH);
  }
}

void Led::off() {
  if (ledAnalog) {
    lumen -= fadeStep;
    if (lumen <= tempLightOff) {
      lumen = tempLightOff;
    }
    analogWrite(pin, int(lumen));
    delayMicroseconds(1000);
  } else {
    digitalWrite(pin, LOW);
  }
}

void Led::setSelected() {
  tempLightOff = lightSelected;
}

void Led::deselect() {
  tempLightOff = lightOff;
}

void Led::setLightOn(int val) {
  lightOn = byte(constrain(val, 0, 255));
}

void Led::setLightOff(int val) {
  lightOff = byte(constrain(val, 0, 255));
}

Now the error is:
ButtonPedal.cpp:3:7: error: redefinition of 'class ButtonPedal'
class ButtonPedal : public Button, public Led {
^~~~~~~~~~~
In file included from sketch\ButtonPedal.cpp:1:0:
sketch\ButtonPedal.h:8:7: note: previous definition of 'class ButtonPedal'
class ButtonPedal : public Button, public Led {
^~~~~~~~~~~
exit status 1
redefinition of 'class ButtonPedal'

I have tried to leave the brakets at the end of constructor input but without succes...

I'm stuck at this point... :confused:

Your ButtonPedal.cpp is wrong. Try:

#include "ButtonPedal.h"

class ButtonPedal : public Button, public Led {
ButtonPedal::ButtonPedal (int _pinButton, int _pinLed, int _programChange) : Button (_pinButton), Led(_pinLed) {
programChange = _programChange;
}

void ButtonPedal::update() {
if (Button::isPressed()) {
midiOut.sendProgramChange(programChange);
} // fine if isPressed
} // fine update

};

ButtonPedal.h is wrong too:

#ifndef BUTTON_PEDAL_H
#define BUTTON_PEDAL_H

#include <Arduino.h>
#include "Button.h"
#include "Led.h"

class ButtonPedal : public Button, public Led {
private:
byte programChange;

public:
ButtonPedal (int _pinButton, int _pinLed, int _programChange) : Button (_pinButton), Led(_pinLed) {};
void update();
};
#endif

Yesss !!!
Good Work and Very Thank You gfvalvo !

Now work fine and I can implement other work for Midi Pedal Board :sunglasses:

Best Regards !!!

Dennis.