###########################
### Code in MicroPython ###
###########################

# VELLEMAN VMA308
# A reed contact switch is a normally open contact, which closes in the presence of a magnetic field. These modules contain a 10K Ω pull-up resistor. 

from machine import Pin # For hardware functions
import time # For time functions

reed_switch = Pin(27, Pin.IN, Pin.PULL_UP) # Set pin 27 as an input with internal pull-up resistor

while True: # Infinite loop
    if reed_switch.value() == 0: # Reads the reed switch's value
        print("Reed switch closed") # If the magnet is close
    else:
        print("Reed switch opened") # If the magnet is far
    time.sleep(0.25) # Delay