Magnetic switch loop

Look at and study the example 02.Digital > StateChangeDetection