I finally got it all to compile without warnings and moved Arduino calls out of constructors:
main.ino:
#include "Puzzle.h"
Puzzle puzzle;
void loop(){
puzzle.loop();
}
void setup(){
puzzle.setup();
}
Box.cpp
#include "Box.h"
#include <Arduino.h>
Box::Box(Debug debug) : _debug(debug)
{
}
void Box::begin()
{
_debug.begin();
pinMode(28, INPUT_PULLUP);
}
Box.h
#ifndef BOX_H
#define BOX_H
#include "Debug.h"
class Box {
private:
Debug _debug;
public:
Box(Debug debug);
void begin();
};
#endif
Debug.cpp
#include "Debug.h"
#include <Arduino.h>
Debug::Debug() : _state(false)
{
}
void Debug::begin()
{
if (_state == false)
{
Serial.begin(9600);
_state = true;
}
}
void Debug::line(const char *messageChar)
{
if (_state)
{
const char *p;
p = messageChar;
while (*p)
{
Serial.print(*p);
p++;
}
newline();
}
}
void Debug::line(int messageInt)
{
if (_state)
{
Serial.print(messageInt);
newline();
}
}
void Debug::newline()
{
if (_state)
{
Serial.println();
}
}
Debug.h
#ifndef DEBUG_H
#define DEBUG_H
class Debug {
private:
bool _state;
public:
Debug();
void begin();
void line(const char *str);
void line(int);
void newline();
};
#endif
Puzzle.cpp
#include "Puzzle.h"
#include "Box.h"
Puzzle::Puzzle()
: _box(_debug)
{
}
void Puzzle::setup()
{
_box.begin();
_debug.begin();
_debug.line("Puzzle Setup");
}
void Puzzle::loop()
{
}
Puzzle.h
#ifndef PUZZLE_H
#define PUZZLE_H
#include "Debug.h"
#include "Box.h"
class Puzzle
{
private:
Debug _debug;
Box _box;
public:
Puzzle();
void setup();
void loop();
};
#endif