
Mick (Customer) asked a question.
having trouble with code recognizing switch closures and going to subroutines. serial monitor recognizes state changes with switches... thanks
- rev 1.00 08/20/2025 7:03 AM -initial release
-
-
- */
- #include <P1AM.h>
- void setup() { // the setup routine runs once:
- Serial.begin(9600); //initialize serial communication at 115200 bits per second
- while (!P1.init()){
- ; //wait for Modules to sign on
- }
- }
- /*
- I/O assignments and Slot assignments
- * *********************************************************************************************
-
- * *********************************************************************************************
- labels for outputs SLOT-1 P1-15TD2 OUTPUT MODULE 15 points of OUTPUT
- */
- //channelLabel N/A = {1, 1}; // SLOT-1 - CH-1: N/A
- channelLabel doorUPrelay = {1, 1}; // SLOT-1 - CH-1: doorUPrelay control relay 1=doorUP / 0=NOT-doorUP
- channelLabel doorDOWNrelay = {1, 2}; // SLOT-1 - CH-2: doorDOWNrelay control relay 1=doorDOWN / 0=NOT-doorDOWN
- channelLabel GREENlight = {1, 12}; // SLOT-1 - CH-12: green light control 1=on / 0= off
- channelLabel AMBERlight = {1, 13}; // SLOT-1 - CH-13: amber light control 1=on / 0= off
- channelLabel REDlight = {1, 14}; // SLOT-1 - CH-14: red light control 1=on / 0= off
- //channelLabel N/A = {1, 15}; // SLOT-1 - CH-15: N/A
- /* ********************************************************************************************
- labels for inputs SLOT-2 P2-16ND3 INPUT MODULE 16 points of INPUT
- */
- channelLabel SAFEdoorSWITCH = {2, 1}; // SLOT-2 - CH-1: safety door interlock switch 1=safe / 0= not-safe
- channelLabel STOPcommandSWITCH = {2, 2}; // SLOT-2 - CH-3: door motion stop switch 1=not-door-stop motion/ 0=stop door motion
- channelLabel UPcommandSWITCH = {2, 3}; // SLOT-2 - CH-2: UPcommandSWITCH door UP mode switch 1=NOT-door-UP / 0= door-UP
- channelLabel DOWNcommandSWITCH = {2, 4}; // SLOT-2 - CH-4: DOWNcommandSWITCH door DOWN mode switch 1=NOT-door-DOWN / 0= door-DOWN
-
- /* ********************************************************************************************
- // * *********************************************************************************************
- /*
- /*
- labels for analog input SLOT-2 P1-04AD-2 ANALOG INPUT MODULE 4-CHANNEL of 0-10 VDC INPUT
- */
- // channelLabel N/A = {2, 1}; // SLOT-1 - CH-1: N/A
- // ********************************************************************************************
- // system variables / flags
- //
- //int UPcommandSWITCH = 1; // check if UPcommandSWITCH flag = 1 NOT-UPcommandSWITCH / 0=UPcommandSWITCH
- //int DOWNcommandSWITCH = 1; // check if DOWNcommandSWITCH flag = 1 NOT-DOWNcommandSWITCH / 0=DOWNcommandSWITCH
- //int STOPdoorSWITCH = 1; // check if STOPdoorSWITCH flag = 1 NOT-STOPdoorSWITCH / 0=STOPdoorSWITCH
- int UPDOORmode = 1; // check if UPDOORmode flag = 1 NOT- door up / 0= door up
- int DOWNDOORmode = 1; // check if DOWNDOORmode flag = 1 NOT- door down / 0= door down
- int STOPDOORmode = 1; // check if STOPDOORmode flag = 1 NOT- door stop / 0= door stop
- int FAULTfatal = 0; // set FAULTfatal flag = 0 not in FAULT / 1= FAULT "int" global variable
- int AMBERLIGHT = 0;
- int REDLIGHT = 0;
- int GREENLIGHT = 0;
- unsigned long x = 0; // the time the delay started
-
- // ********************************************************************************
- /* *********************************************************************************************
- * scan UP/DOWN control switch zone
- */
- void loop() // the loop routine to scan UP/DOWN control switch zone
- { scanCONTROLbuttons();
- }
- void scanCONTROLbuttons()
- {
- Serial.println(UPDOORmode); // check status if x-axis has homed
- P1.writeDiscrete(HIGH, GREENlight); //green light control= ON
- delay(250); //wait .25 second
- //P1.writeDiscrete(HIGH,doorUPrelay); // doorUPrelay control relay 1=doorUP / 0=NOT-doorUP
- //P1.writeDiscrete(HIGH,doorDOWNrelay); // doorUPrelay control relay 1=doorDOWN / 0=NOT-doorDOWN
- //
- // check UP door Switch for status: = 1 NOT-UPcommandSWITCH / 0=UPcommandSWITCH
- UPDOORmode = P1.readDiscrete(UPcommandSWITCH); // check if UPcommandSWITCH = 1 NOT-UPcommandSWITCH / 0=UPcommandSWITCH
- if (UPDOORmode == 1) // check if UPDOORmode flag = 1 NOT- door up / 0= door up
- {
- // P1.writeDiscrete(HIGH,doorUPrelay); // doorUPrelay control relay 1=doorUP / 0=NOT-doorUP
- MOVEdoorUP; // gosub MOVEdoorUP subroutine
- }
- //
- // check DOWN door Switch for status: = 1 NOT-DOWNcommandSWITCH / 0=DOWNcommandSWITCH
- DOWNDOORmode = P1.readDiscrete(DOWNcommandSWITCH); // check if DOWNcommandSWITCH = 1 NOT-DOWNcommandSWITCH / 0=DOWNcommandSWITCH
- if (DOWNDOORmode == 1) // check if DOWNDOORmode flag = 1 NOT- door down / 0= door down
- {
- MOVEdoorDOWN; // gosub MOVEdoorDOWN subroutine
- }
- //
- // check STOP door Switch for status: = 1 NOT-STOPcommandSWITCH / 0=STOPcommandSWITCH
- STOPDOORmode = P1.readDiscrete(STOPcommandSWITCH); // check if STOPcommandSWITCH = 1 NOT-STOPommandSWITCH / 0=STOPcommandSWITCH
- if (STOPDOORmode == 1) // check if STOPDOORmode flag = 1 NOT- door stop / 0= door stop
- {
- STOPdoor; // gosub STOPdoor subroutine
- }
-
- P1.writeDiscrete(LOW, GREENlight); //green ight control= OFF
- delay(250); //wait .5 second
- }
-
- // **********************************************************************************
- // **********************************************************************************
- // move door up - start door movement UP
- //
- void MOVEdoorUP() // use void because variables declared globaly
- {
- P1.writeDiscrete(HIGH, AMBERlight); //amber light control 1= on
- P1.writeDiscrete(LOW,doorDOWNrelay); // doorDOWNrelay control relay 1=doorDOWN / 0=NOT-doorDOWN
- delay(250); //wait .25 second
- P1.writeDiscrete(HIGH,doorUPrelay); // doorUPrelay control relay 1=doorUP / 0=NOT-doorUP
- }
-
- // **********************************************************************************
- // **********************************************************************************
- // move door down - start door movement DOWN
- //
- void MOVEdoorDOWN() // use void because variables declared globaly
- {
- P1.writeDiscrete(HIGH, AMBERlight); //green light control 1= on
- P1.writeDiscrete(LOW,doorUPrelay); // doorUPrelay control relay 1=doorUP / 0=NOT-doorUP
- delay(250); //wait .25 second
- P1.writeDiscrete(HIGH,doorDOWNrelay); // doorUPrelay control relay 1=doorDOWN / 0=NOT-doorDOWN
- }
-
- // **********************************************************************************
- // **********************************************************************************
- // stop door - stop door movement
- //
- void STOPdoor() // use void because variables declared globaly
- {
- P1.writeDiscrete(LOW,doorUPrelay); // doorUPrelay control relay 1=doorUP / 0=NOT-doorUP
- P1.writeDiscrete(LOW,doorDOWNrelay); // doorDOWNrelay control relay 1=doorDOWN / 0=NOT-doorDOWN
- P1.writeDiscrete(LOW, GREENlight); //green light control 0= oFF
- }
-
- // **********************************************************************************
- // **********************************************************************************
-
-
- // **********************************************************************************
From: https://docs.arduino.cc/learn/programming/functions/ :
"As you can see, even if a function does not have parameters and no returns is expected "(" and ")" brackets plus ";" must be given."
Is the compiler giving any errors? I don't know off hand, what the compiler "thinks' of:
Note that in loop() you do call "scanCONTROLbuttons();" with the brackets
Yes without the () it's not a function call but an expression that refers to the function itself (its address). So it basically does nothing but it will compile.
Just add the () to the function calls and you should be good.