Door Magnetic Switch
Overview
When a magnet approaches, the reed switch closes and outputs a high level; otherwise, it outputs a low level.
Technical Specifications
Operating voltage: VCC 3.3V -5V
Module dimensions: 24*48mm
Mounting: 2 plastic building block compatible through-holes
Data type: Triggered–1 Not triggered–0
Pin Definition
Pin |
Definition |
|---|---|
GND |
Ground |
VCC |
Power |
DO |
Digital output |
NC |
Not connected |
Example Code
Use a magnetic object (such as a magnet) to approach the magnetic switch to trigger it.
from mpython import *
p0 = MPythonPin(0, PinMode.IN)
import time
def boolean_P0():
return p0.read_digital() == 1
while True:
if boolean_P0():
rgb.fill((int(255), int(0), int(0)))
rgb.write()
time.sleep_ms(1)
time.sleep(1)
else:
rgb.fill( (0, 0, 0) )
rgb.write()
time.sleep_ms(1)