On object creation only questions marks on serial monitor

With the following simple code, the serial monitor works fine. It just displays "I am here!".

#include "scb.h"

//Scb Scb1(13, 12, 11, 10, 9);


void setup() {
Serial.begin(9600);

}

void loop() {

delay(2000);
Serial.println("I am here!");

}

I've written the following class:

#ifndef Scb_h

#define Scb_h

#include "Arduino.h"


class Scb {
  
  private:
	const byte POWER_STEPWIDTH_PERCENT = 10; // Stepwidth for increment/decrement on digital Scb input
	const byte MIN_POWER_PERCENT = 0;  // min. power percent
	const byte MAX_POWER_PERCENT = 100; // max. power percent
	byte powerStepUpPin;  // pin to increase power
	byte powerStepDownPin; // pin to decrease power
	byte confirmPin; // pin to confirm power changes
	byte errorPin; // pin to receive error state
	byte rdyPin;  // pin to receive ready stat (FC booted)
	byte actPowerLevelPercent;  // actual power Level
	byte newPowerLevelPercent; // new power Level set by stepup / stepdown (to be confirmed afterwards)
	const unsigned long signalLengthMillis = 20;  // signal interval for stepup / stepdown
	
	void setPowerStepUpPin(byte _powerStepUpPin);
	void setPowerStepDownPin(byte _powerStepDownPin);
	void setConfirmPin(byte _confirmPin);
	void setReadyPin(byte _readyPin);
	void setErrorPin(byte _errorPin);
	void stepUp(byte _steps);
	void stepDown(byte _steps);
	void confirm();  // apply power setting changes
	void initializeFcPowerLevel();

  public:
  
    // Construtor
    Scb(byte _powerStepUpPin, byte _powerStepDownPin, byte _confirmPin, byte _rdyPin, byte _errorPin);
	
	void setPowerLevel(byte _newPowerLevelPercent);
	
	boolean isReady();
	
	boolean hasError();

};
	
#endif

In addition, the following cpp file:

#include "Arduino.h"

#include "scb.h"

Scb::Scb (byte _powerStepUpPin, byte _powerStepDownPin, byte _confirmPin, byte _rdyPin, byte _errorPin) {
	Serial.println("constructor...");
	delay(2000);
	Serial.println("constructor 2...");
	delay(2000);
	setPowerStepUpPin(_powerStepUpPin);
	setPowerStepDownPin(_powerStepDownPin);
	setConfirmPin(_confirmPin);
	setReadyPin(_rdyPin);
	setErrorPin(_errorPin);
	actPowerLevelPercent = 0;
	newPowerLevelPercent = 0;
	initializeFcPowerLevel();
}
	
void Scb::setPowerStepUpPin(byte _powerStepUpPin) {
	powerStepUpPin = _powerStepUpPin;
	pinMode(powerStepUpPin, OUTPUT);
}

void Scb::setPowerStepDownPin(byte _powerStepDownPin) {
	powerStepDownPin = _powerStepDownPin;
	pinMode(powerStepDownPin, OUTPUT);
}

void Scb::setConfirmPin(byte _confirmPin) {
	confirmPin = _confirmPin;
	pinMode(confirmPin, OUTPUT);
}

void Scb::setReadyPin(byte _rdyPin) {
	rdyPin = _rdyPin;
	pinMode(rdyPin, INPUT);
}

void Scb::setErrorPin(byte _errorPin) {
	errorPin = _errorPin;
	pinMode(errorPin, INPUT);
}

void Scb::stepUp(byte _steps) {
	
	for (byte i = 0; i < _steps; i++) {
	digitalWrite(powerStepUpPin, HIGH);
	delay(signalLengthMillis);
	digitalWrite(powerStepUpPin, LOW);
	delay(signalLengthMillis);
	};
}

void Scb::stepDown(byte _steps) {
	for (byte i = 0; i < _steps; i++) {
	digitalWrite(powerStepDownPin, HIGH);
	delay(signalLengthMillis);
	digitalWrite(powerStepDownPin, LOW);
	delay(signalLengthMillis);
	};
}

void Scb::confirm() { // apply power setting changes
	digitalWrite(confirmPin, HIGH);
	delay(signalLengthMillis);
	digitalWrite(confirmPin, LOW);
}

void Scb::setPowerLevel(byte _newPowerLevelPercent) {
	long stepDiff = (_newPowerLevelPercent - actPowerLevelPercent)/POWER_STEPWIDTH_PERCENT;  // cal. difference
	if (stepDiff > 0) {stepUp(byte(stepDiff));}
	else if (stepDiff < 0) {stepDown(byte(abs(stepDiff)));}  // use absolute value
	confirm(); // apply new value
	actPowerLevelPercent = _newPowerLevelPercent;
}

void Scb::initializeFcPowerLevel() {  // set power to zero. Go as many steps down as possible
	stepDown(byte(MAX_POWER_PERCENT / POWER_STEPWIDTH_PERCENT));
}

boolean Scb::isReady() {
	Serial.println("checking if ready...");
	return digitalRead(rdyPin); // if set to HIGH, Fc is ready
}

boolean Scb::hasError() {
	return !digitalRead(errorPin);  // if set to LOW, Fc is in errorstate
}

I put in the

Scb Scb1(13, 12, 11, 10, 9);

again. Compilation finishes without error.

The serial monitor just says "?". Also function calls on object Scb1 don't work at all. Obviously the codes get stuck at some point, since not even the "I am here" is shown any more. Any idea what might have gone wrong?

The Serial port is started in setup(). Your class's constructor runs before setup(). You try to print to the Serial port from the constructor. That's a problem.

sebert:
Any idea what might have gone wrong?

Touching the hardware in a global constructor. Not just Serial. Like all other Arduino related classes, yours should have a begin method.

In general, that's just good practice. Constructors should do just enough to bring an object to a stable state (e.g. no uninitialized members) and no more.

The combination of both of you solved the problem. It was important to move any specific function calls away from the constructor and put it into the begin() method. Thanks!

New code (just for information in case somebody has similar problems):

#include "scb.h"

Scb Scb1;

void setup() {
Serial.begin(9600);
Scb1.begin(13, 12, 11, 10, 9);

}

New cpp-file:

Scb::Scb () {

}

void Scb::begin(byte _powerStepUpPin, byte _powerStepDownPin, byte _confirmPin, byte _rdyPin, byte _errorPin) {
	setPowerStepUpPin(_powerStepUpPin);
	setPowerStepDownPin(_powerStepDownPin);
	setConfirmPin(_confirmPin);
	setReadyPin(_rdyPin);
	setErrorPin(_errorPin);
	actPowerLevelPercent = 0;
	newPowerLevelPercent = 0;
	initializeFcPowerLevel();
}