Thx for your questions and hints - they took me further!
The size of the sketch is because of the functionality of my watering system: I incorporated a web server with GET- & POST-Requests, some classes for web-configurable Sensors and Devices and a web-configurable WorkSet to specify individual watering rules. I am sure that refactoring might lower the resulting sketsch size, but not for 30 % to get below 64 k - and the project is not done yet.
And, to answer your question, in my test I did Serial.print the raw value like
byte r1 = 9;
r1 = digitalRead(r1);
Serial.println(r1);
In my further tests I figured out that digitalRead finally DOES NOT returns false results. The input pins are configured with internal pullups and when the attached buttons are open I can measure apx 4.85 V at the pin, when I close the buttons to GND the voltage drops to some 110 mV. All this is clearly visible at my oscillocope.
During setup() I can see the voltage drop at the oscilloscope when class WorkSet is instantiated. In the constructor of this class I read the specified config from a SD-File and create new Sensor-, new Device- and new Condition-Objects. The reason for the voltage to drop at a certain moment is when I just insert 3 new Byte-Members in my class declaration (see the 3 lines marked like '<<< MAGIC') ... without any reference somewhere in my code:
class WorkSet {
private:
bool _isValid = false; // Tells whether this workset holds valid data
bool _isWfmPossible = false; // Tells whether WFM-data is present und complete to activate WFM-checks
bool _isSingleActorMode = true; // Operate only one device at a time, although more than one may meet their switching condition
public:
// Member
char name[lenFilename + 1] = {0}; // Filename of the WorkSet (including extension .ws)
char error[lenError + 1] = {0}; // Last error that has occurred
time_t errorTime = 0; // Time the last error occurred
uint8_t errorState = errCleared; // The current errorState (see Workset ERROR states above)
byte wiredAnalog; // <<< MAGIC after insert //Number of physically wired analog sensors
byte wiredBinary; // <<< MAGIC after insert //Number of physically wired binary sensors
byte wiredDevices; // <<< MAGIC after insert //Number of physically wired digital devices
byte numSensors = 0; // Number of Sensors attached
byte numDevices = 0; // Number of Devices attached
Sensor **ppSensors; // Sensors handled in this WorkSet
Device **ppDevices; // Devices handled in this WorkSet
int8_t state = stateUnknown; // Current state of this WorkSet (see Device-, Sensor- and WorkSet-states above)
int8_t stateSaved = stateUnknown; // Holds the state saved before different actions, e.g. before activating WFM
time_t wfmLastOnOff = 0; // Last time a device has been switched on or off
unsigned long wfmLastCount = 0; // Reading of the water counter at the time the last device was switched on or off
int8_t wfmLearnMode = learnOff; // Shows whether Learning Mode is on
int8_t wfmAlertedDeviation = 0; // Deviation already reported (for this value an alert already has been sent to LCD and log)
int8_t wfmAllowedDeviation = 0; // Threshold for the allowed deviation between counted and calculated pulses within regular operations
// int8_t allowes a range from -127 to +127 and maxDeviation has to be within this range.
// Deviation values greater than this threshold causes the Error-LED to be switched on.
int16_t wfmCurrentDeviation = 0; // Records the current deviation
uint16_t wfmLostPulses = 0; // Holds the last reported (to the LCD) and yet unconfirmed number of pulses without active device
bool wfmIsPulseCalculated = false; // Tells wheter WFM pulses were calculated during operational WFM
bool wfmIsPulseCounted = false; // Tells wheter a second WFM pulse was detected after the first WFM start pulse (after the last device was switched on)
// Constructor
WorkSet(char *filename); // Constructor
// Functions
bool checkDevices(); // Checks whether Devices have to be switched on or off
bool checkSwitching(Device *d, char *currDay, char *onlyTime); // Checks whether uptimes and condition are met to switch on the device
bool checkUptimes(Device *d, char *currDay, char *onlyTime); // Checks uptimes whether the device has to be switched on or off
// currDay = "Mon"-"Son"/"***" (len = 4 including \0)
// onlyTime = "0800", "1015" (len = 5 including \0)
bool checkValues(Device *d); // Checks values of conditions whether the device has to be switched on or off
void degradeSequence(uint8_t seq); // Degrades the sequence of all devices ordered past the provided sequence
// (Used after a seqenced device was switched on in ::checkDevices)
void dump(byte typeOfDest, byte typeOfLog); // Dumps the properties of the entire WorkSet to Serial and/or the specified logfiles or to both
int8_t findActiveDevice(); // Returns the index of the first device which is not deactivated
int8_t findDeviceInState(int8_t state); // Returns the index of the first device found in the the provided state or -1 if none was found
int8_t findDeviceRunning(); // Returns the index of the first device found with isOn()==true or -1 if none was found
int8_t findDeviceToSwitch(); // Returns the index of the device to switch on next according to sequence
int8_t findMaxSequence(); // Returns the the maximum sequence currently found in a device or 0 if no device has set a sequence
int8_t findMinSequence(); // Returns the the minimum sequence currently found in a device or 0 if no device has set a sequence
void getDeviceStates(char *tBuf); // Fills the provided character buffer with the state of all configured devices:
int getSize(); // Returns the size in Bytes of the entire WorkSet and all included Sensors, Devices, Uptimes and Conditions
bool isActive(); // Returns whether this WorkSet is active or not
bool isValid(); // Returns true, if the object was successfully created from an WorkSet-file
bool isWfmPossible(); // Returns true, if WFM-data is present for all configured devices
bool isSingleActorMode(); // Returns true, if only device is allowed to operate at a time, although more than one may meet their switching condition
bool loadDeviceWfms(); // Loads the devices .lastAvgWf values from the file 'WorkSet-name'.wf (in case it exists)
void processCmd(char *); // Processes the specified command for the WorkSet
bool readLine(File, char *, int, int *); // Reads the next line of the specified file with buffer lenght check
bool readLine(File, char *); // Reads the next line of the specified file, no buffer lenght check
float readSensorValue(char anDi, byte pin); // Reads and returns the current value for the specified sensor
void relocateSequences(); // Relocates the sequence of all devices for the provided gap so the first sequence starts at 1
void resequenceDevices(char *currDay, char *onlyTime); // Resequences all unsequenced devices in stateOff having positively completed their check to switch on
bool saveDeviceWfms(); // Saves the devices .lastAvgWf values to the file 'WorkSet-name'.wf
void setState(int8_t); // Sets the WorkSet to the specified state-byte
void wfmCancel(); // Aborts a possibly ongoing water flow measurement
void wfmStartNextOrEndWfm(); // Searches for a device pending for WFM and initiates it (or end the WFM)
};
Tracked effects:
- With these 3 new lines the voltage changes to LOW during setup() repectively the creation of the WorkSet with its Sensors, Devices, Uptimes, Conditions.
- Whithout these 3 new lines my scetch works and the voltage stays HIGH
- When I comment one of these 3 membes leaving just 2 the voltage stays HIGH
- When I move the 3 lines down to the end of the member declarations right before the declaration of the ctor the voltage stays HIGH
- When I move them at the very beginning before bool _isValid the voltage changes to LOW
So I changed my config file (different numbers of sensors/devices/conditions) but the effect stays. Only the moment the voltage goes down changes - like it was influenced by the number of Bytes I allocated with my 'new Sensor' & 'new Device' statements.
I can not imagine a reason for this strange behavior ... ?
I think I should close this topic and open a new one with a corrected description!