I stripped my code to the minimum and I just don't understand why I am getting pin 13 toggling and Serial.write not working in one case but not in the other.
I have three files: Debug the arduino sketch, Debug.h (the library header file) and Debug.cpp (the C++ library file)
With Debug.cpp as is shown below, I get pin 13 toggling on an UNO board and nothing is printed to serial out.
If I replace the "array[halfarraySize];" with "float array[halfarraySize];" in Debug.cpp, pin13 and the serial print behave properly. Can you please explain what I am doing wrong and/or what is going on?
Thanks in advance!
Debug sketch:
#include <Debug.h>
const int arraySize=118;
debugClass debug_object(arraySize);
void setup() {
Serial.begin(115200);
Serial.write("test");
}
void loop() {
}
Debug.h:
#ifndef Debug_h
#define Debug_h
#include "Arduino.h"
class debugClass{
public:
debugClass(const int arraySize);
// Keep as many variables private as possible
private:
int halfarraySize;
float array[];
};
#endif
Debug.cpp:
#include "Debug.h"
debugClass::debugClass(const int arraySize){
const int halfarraySize = arraySize/2;
// This needs to be declared or prints have issues
array[halfarraySize];
for(int i = 0; i < halfarraySize; i++){
array[i] = 0;
}
}