Hello community,
The attached code runs smoothly on a Arduino Nano and Arduino Uno R3 but completely fails on an Arduino Nano ESP32.
The code here won't display the final "Setup done ..". If the code is only slightly change, Arduino keeps restarting endlessly.
I've stripped the code down to only a few lines. It is about singleton classes.
Why does it not run on an Arduino Nano ESP32 but on several different boards?
Anybody with an explanation?
Thanks a lot Michael
MeasWaggon.ino
#include "HardwareTimerESP32.h"
void setup() {
Serial.begin(115200);
delay(5000);
Serial.println("Project is starting up ....");
HardwareTimerESP32::getInstance();
HardwareTimerESP32::getInstance().Initialize();
Serial.println("Setup done ...");
}
// the loop function runs over and over again forever
void loop() {
}
HardwaretimerESP32.h
#ifndef _HARDWARETIMER_h
#define _HARDWARETIMER_h
#include "Arduino.h"
class HardwareTimerESP32 {
private:
// === Required for Singletons ===
HardwareTimerESP32();
HardwareTimerESP32(const HardwareTimerESP32&) = delete;
HardwareTimerESP32& operator=(const HardwareTimerESP32&) = delete;
public:
// for singleton
static HardwareTimerESP32& getInstance();
int SetTimerInterval(int timeMs);
void Initialize();
void Loop();
protected:
};
#endif
HardwareTimerESP32.cpp
#include "HardwareTimerESP32.h"
#include "Arduino.h"
// -----------------------------------------------------------------
// Constructor
// -----------------------------------------------------------------
HardwareTimerESP32::HardwareTimerESP32() {
// Initialization code, if needed
}
// -----------------------------------------------------------------
// To get/create the singleton
// -----------------------------------------------------------------
HardwareTimerESP32& HardwareTimerESP32::getInstance() {
static HardwareTimerESP32 instance;
return instance;
}
int HardwareTimerESP32::SetTimerInterval(int timeMs) {
Serial.println("HardwareTimerESP32.SetTimerInterval ...");
}
void HardwareTimerESP32::Initialize() {
Serial.println("HardwareTimerESP32.Initialize ...");
SetTimerInterval(1000);
}
void HardwareTimerESP32::Loop() {
}