模組簡介
FC-51 IR Sensor Module
This is the schematic of the IR sensor FC-51
電路圖
程式列表(IO輪巡式)
Blockly
Python
"""
EPY Sensor
-----------------
3V3 VCC
GND GND
P4 OUT
VIN
CDS
"""
from machine import LED
from machine import Pin
from machine import Switch
import utime
from machine import RTC
KeyA = None
P4 = None
rtc = None
ledR = None
ledG = None
KeyA = Switch('keya')
rtc = RTC()
ledR = LED('ledr')
ledG = LED('ledg')
ledG.off()
P4 = Pin(Pin.board.P4,Pin.IN)
while True:
if (P4.value()) == 0:
ledR.toggle()
ledG.off()
else:
ledR.off()
ledG.toggle()
if (KeyA.value()) == True:
break
utime.sleep_ms( 500 )
執行結果
沒有物體接近綠燈閃爍
有物體接近紅燈閃爍