The contact code uses the ability of the CPX to detect the voltage connected to a pin and interpret that as a digital value, a 1 or a 0. Digital values are sometimes referred to as ON or OFF, HIGH or LOW, and TRUE or FALSE. For the CPX a voltage of 3.3 volts is digitally read as a 1 and a voltage of 0 volts is digitally read as a 0. Going forward we will refer to these states as HIGH and LOW
In the contact mode a special command set pull pin to up is used to set pin A6 to 3.3 volts unless it is connected to GND (which is at 0 volts). This means that until we connect pin A6 to GND it will always digital read a HIGH.
Using a digital read, the If statement checks to see if the pin A6 is LOW, which means it is connected to GND. THEN it will do what is inside of it. If A6 is HIGH, meaning it is not connected to GND then the code in the ELSE section will run.
Digital read = LOW = Contact has been made
Digital read = HIGH = No contact has been made