Why in easyC does 1 = off 0 = on for IO

I can understand active low inputs and outputs. Do you teach the kids to create a constant at the start of the program for IO_TRUE = 0 and IO_FALSE = 1 then use these in your Boolean statements. I know the syntax is wrong with-out the main method and what not. I’m not real hi speed with C Code but you get the point.


#define IO_TRUE	0
#define IO_FALSE	1
#define TRUE	1
#define FALSE	0

while (TRUE){

    switch = getdigital(1);

    if (switch == IO_TRUE){ // switch is pressed input pulled LOW
        // Do something
        setDigitalOut(2,IO_TRUE); //Turn on Output 2
    }else{
        setDigitalOut(2,IO_FALSE); //Turn off Output 2
    }
}

}

I’d make the two defines

#define ON 0
#define OFF 1

Then the IF statement makes a little more sense:

if (switch == ON){ // switch is pressed input pulled LOW
    // Do something
    setDigitalOut(2, ON); //Turn on Output 2

On and off are a little easier that IO_True and IO_False

I like it. From my PLC Background I see true/false but the kids may not be there yet