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... 