CODE: Outside unit
Code: [Local Link Removed for Guests]
cls
PIN.MODE 5, output 'alive indicator led
PIN(5) = 0
i = 0
trg = 0
dist = 0
vlt = ADC
batt = 0
msg$ = "0"
MAC1$ = "86:F3:EB:10:0B:2C" 'house
espnow.begin
espnow.add_peer MAC1$
'espnow.add_peer MAC2$
timer0 700, update
wait
update:
PIN(5) = 0
dist = DISTANCE(14,4)
pause 200
'if dist < 300 then trg = trg + 1 else trg = 0 ' uncheck if needed
'if trg >= 2 gosub alert ' uncheck if needed
if dist < 300 gosub alert
return
alert:
vlt = ADC
PIN(5) = 1
batt = CONVERT.MAP(vlt, 708, 1006, 12, 17)* 100 + 6 '+6 is for calibration
msg$ = str$(batt)
EspNow.Write(msg$)
pause 300
PIN(5) = 0
trg = 0
return
CODE: Inside unit
Code: [Local Link Removed for Guests]
cls
pin.Mode 4, output 'blue led low battery alert
pin.Mode 5, output 'red led
pin.mode 12, input, pullup
INTERRUPT 12, display
pin.Mode 14, output 'bell or buzzer
PIN(4) = 1
PIN(5) = 0 'alive indicator on boot
PIN(14) = 1 'alive indicator on boot
pause 500
PIN(14) = 0
PIN(5) = 1
TM1637.SETUP 13, 16
batt$ = "0000"
trigs = 0
TM1637.PRINT str$(trigs), 4, 0
espnow.begin
onEspNowMsg message
autorefresh 1000
wlog "listening..."
wait
message:
trigs = trigs + 1
TM1637.PRINT str$(trigs), 4, 0
batt$ = espnow.read$
if val(batt$) > 120 PIN(5) = 0 else PIN(4) = 0
PIN(14) = 1
pause 1000
PIN(14) = 0
pause 10000
PIN(4) = 1
PIN(5) = 1
return
display:
TM1637.PRINT batt$, 4, 255
if pin(12) = 0 return
TM1637.PRINT str$(trigs), 4, 0
refresh
return