限位开关

../../../../_images/%E9%99%90%E4%BD%8D%E5%BC%80%E5%85%B3.png

概述

按压式的开关数字输入模块,按下为高电平输出,否则输出低电平。

技术参数

工作电压: VCC 3.3V -5V

模块尺寸:24*48mm

固定安装:2个兼容塑料积木通孔

数据类型:触发--1 未触发--0

引脚定义

引脚

定义

GND

地

VCC

电源

DO

数字输出

NC

空

示例程序

当限位开关被触发时,掌控板RGB灯亮。

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)
../../../../_images/%E9%99%90%E4%BD%8D%E5%BC%80%E5%85%B31.png