hi all
thanks in advance for any help
question:
would like to call a function, pass a struct object as a parameter, in order for the function to modify struct members.
Please assist.
***** tried following code but it did not work *****
A/ function definition
void digitalRead ( &relay ) {
B/ calling function
void loop() {
digitalRead( relay );
note: have created another version for this function to access struct members as
relay. as opposed to relay1.
2/
defined global variable relay1 type struct relay
// physical variables
typedef struct {
const int NC_pin = 2; // set relay 1 NC pin
const int NO_pin = 3; // set relay 1 NO pin
const int Coil_pin = 12; // set relay 1 coil pin
bool NC = false, NO = false, Coil = false;
bool bRise = false, bFall = false, bTiming = false;
unsigned long lastDebounceTime = 0; // the last time the input pin was toggled
} relay;
relay relay1;
3/
function
note: when creating a generic function to handle many relays, have modified this function to access object
relay.
as opposed to
relay1.
...
void digitalRead1 ( ) {
if( digitalRead(relay1.NC_pin) && !relay1.NC ) {
relay1.bRise = true;
relay1.lastDebounceTime = millis();
relay1.bTiming = true;
}
else {
relay1.bRise = false;
}
if( !digitalRead(relay1.NC_pin) && relay1.NC ) {
relay1.bFall = true;
relay1.lastDebounceTime = millis();
relay1.bTiming = true;
}
else {
relay1.bFall = false;
}
// read the current button pin state
relay1.NC = digitalRead( relay1.NC_pin );
relay1.NO = digitalRead( relay1.NO_pin );
// If the input changed, due to noise or pressing:
if ( ((millis() - relay1.lastDebounceTime) > debounceDelay) && relay1.bTiming ) {
relay1.bTiming = false;
Serial.println( "***** relay1_NC settled *****" );
Serial.println( relay1.lastDebounceTime );
Serial.println( millis() );
Serial.println( "relay1.NC" );
Serial.println( relay1.NC );
Serial.println( "\n" );
// for testing purpose only
if( relay1.NC ) {
digitalWrite(orangeLED_pin, HIGH);
}
else {
digitalWrite(orangeLED_pin, LOW);
}
}
}