Hallo,
Ich bin ein Anfänger in der Programmierung und benötige Hilfe. Um meinen Code übersichtlich zu halten, möchte ich OOP einsetzen. Mein zukünftiger Brauautomat besteht aus mehreren Komponenten (DC Motor, Pumpen, DS8020, Relais, LCD, Taster, Encoder, RTC und Arduino MEGA 2560).
Die Idee ist, eine Klasse "Device" zu erzeugen, die alle Komponenten als private Member besitzt. Das hätte den Vorteil der Kapselung und auch der größeren Übersichtlichkeit im Hauptprogramm, weil ich dort nicht alle Komponenten einzeln ansteuern möchte. In dem vereinfachten Beispiel besteht das Gerät aus einem LCD-Display und einer LED. Ich bekomme es nicht zum Laufen und bitte um Hilfe.
Die Fehlermeldung ist: no matching function for call to 'LiquidCrystal::LiquidCrystal()
Ich hoffe es sind nicht noch zu viele andere Fehler drin und die Herangehensweise ist grundsätzlich vernünftig. Jede Hilfe ist willkommen! - Vielen Dank!
**Das Hauptprogramm:**
#include <LiquidCrystal.h>
#include "Led.h"
#include "Device.h"
LiquidCrystal lcd(42, 40, 38, 36, 34, 32);
Led led(13);
Device device(lcd, led);
void setup()
{
device.init();
device.helloWorld();
}
void loop()
{
}
**LED.h**
#ifndef LED_H
#define LED_H
#include <Arduino.h>
class Led
{
private:
byte pin;
public:
Led(){} // default constructur
Led(byte pin);
void init();
void on();
void off();
};
#endif
**LED.cpp**
#include "Led.h"
Led::Led(byte pin)
{
this->pin = pin;
}
void Led::init()
{
pinMode (pin, OUTPUT);
}
void Led::on()
{
digitalWrite(pin, HIGH);
}
void Led::off()
{
digitalWrite(pin, LOW);
}
**DEVICE.h**
#ifndef DEVICE_H
#define DEVICE_H
#include <Arduino.h>
#include <LiquidCrystal.h>
#include "Led.h"
class Device
{
private:
LiquidCrystal deviceLcd;
Led deviceLed;
public:
Device(){}
Device(LiquidCrystal lcd , Led led);
void init();
void helloWorld();
};
#endif
**DEVICE.cpp**
#include "Device.h"
Device::Device(LiquidCrystal lcd , Led led)
{
deviceLcd=lcd;
deviceLed=led;
}
void Device::init()
{
deviceLed.init();
deviceLed.off();
deviceLcd.begin(16, 2);
}
void Device::helloWorld()
{
deviceLed.on();
deviceLcd.setCursor(0,0);
deviceLcd.print("Hello World");
}
Led.h (234 Bytes)
Led.cpp (220 Bytes)
Device.h (491 Bytes)
Device.cpp (504 Bytes)
Main.ino (327 Bytes)