I am working on a project where i created my own class to encapsulate u8glib to simulate a console output. However, i have run into problems with my constructor. To simplify the code I have recreated the same issue in a simpler project.
My problem is that i don't know why my constructor for MyClass is never called (led 13 is not blinking, and no serial output) and further why Loop is not run (led 13 is not blinking).
I bet the reason is very simple, but right now I'm stuck. Any help would be greatly appreciated!
Test_Class_Constructor.ino
#include "MyClass.h"
const int led = 13;
MyClass mc(led);
//SETUP
void setup(void)
{
mc.printMessage();
}
void loop(void)
{
// Do some slow blinking
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
MyClass.h
#ifndef MyClass_h
#include <Arduino.h>
class MyClass
{
public:
MyClass(int sPin);
void printMessage(void);
private:
int state;
int statusPin;
};
#endif
MyClass.cpp
#include "MyClass.h"
MyClass::MyClass(int sPin)
{
Serial.begin(9600);
Serial.println("Initializing MyClass...");
statusPin = sPin;
state = 1;
pinMode(statusPin, OUTPUT);
// Do some fast blinking
digitalWrite(statusPin, HIGH); delay(125); digitalWrite(statusPin, LOW); delay(50); digitalWrite(statusPin, HIGH); delay(125); digitalWrite(statusPin, LOW); delay(600);
digitalWrite(statusPin, HIGH); delay(125); digitalWrite(statusPin, LOW); delay(50); digitalWrite(statusPin, HIGH); delay(125); digitalWrite(statusPin, LOW); delay(600);
digitalWrite(statusPin, HIGH); delay(125); digitalWrite(statusPin, LOW); delay(50); digitalWrite(statusPin, HIGH); delay(125); digitalWrite(statusPin, LOW); delay(600);
digitalWrite(statusPin, HIGH); delay(125); digitalWrite(statusPin, LOW); delay(50); digitalWrite(statusPin, HIGH); delay(125); digitalWrite(statusPin, LOW); delay(600);
digitalWrite(statusPin, HIGH); delay(125); digitalWrite(statusPin, LOW); delay(50); digitalWrite(statusPin, HIGH); delay(125); digitalWrite(statusPin, LOW); delay(600);
digitalWrite(statusPin, HIGH); delay(125); digitalWrite(statusPin, LOW); delay(50); digitalWrite(statusPin, HIGH); delay(125); digitalWrite(statusPin, LOW); delay(600);
Serial.println("MyClass initialized.");
}
void MyClass::printMessage()
{
Serial.println("Message");
}