This version compiles without error or warning and seems to produce reasonable output:
class InputPeripherals
{
public:
InputPeripherals();
void init(int buttonAdress, void (*funkce) (byte number));
void updateClass();
private:
int _pin;
void (*_fooShowNumber) (byte number);
};
class OutputPeripherals
{
public:
OutputPeripherals();
void init(); // !!! správně by tady mělo být vkládání pole(_leds[8] ale pro zjednodušení jsem ho vynechal
static void number(byte number);
private:
static int _leds[8];
};
InputPeripherals buttonA;
OutputPeripherals leds;
void setup()
{
delay(20);
Serial.begin(115200);
delay(20);
Serial.println("\nTransfer started \n\n");
leds.init();
leds.number(5);
buttonA.init(12, OutputPeripherals::number);
}
void loop()
{
buttonA.updateClass();
delay(500);
leds.number(8);
delay(500);
Serial.print("end loop\n\n");
delay(10000);
}
InputPeripherals::InputPeripherals() {}
void InputPeripherals::init(int buttonAdress, void (*foo) (byte number))
{
Serial.println("Output set INPUT_PULLUP");
pinMode(buttonAdress, INPUT_PULLUP);
_pin = buttonAdress;
_fooShowNumber = foo;
}
void InputPeripherals::updateClass()
{
Serial.print("Button value is: ");
Serial.println(digitalRead(_pin));
if (digitalRead(_pin) == 0)
{
Serial.println("calling 3");
_fooShowNumber(3);
}
else
{
Serial.println("calling 1");
_fooShowNumber(1);
}
}
int OutputPeripherals::_leds[8] = {3, 4, 5, 6, 7, 8, 9, 10};
OutputPeripherals::OutputPeripherals() {}
void OutputPeripherals::init()
{
for (int i = 0; i < 8; i++)
{
pinMode(_leds[i], OUTPUT);
}
}
void OutputPeripherals::number(byte number)
{
Serial.print("Incomming number: ");
Serial.println(number);
for (int i = 0; i < 8; i++)
{
digitalWrite(_leds[i], number & (0x01 << i));
}
}