This is the code for the MK1-S1 Ultrasonic Ruler project.
It displays the distance to an object in cm on the Show page.
Program
---
MK1-S1 Ultrasonic Ruler Program
For Me-Kit project MK1-S1 Ultrasonic Ruler
Displays the distance to an object in cm on the Show page.
---
prog_vars =
d/count 0
prog_vars.
prog_start =
pclear
-- Show title
ptl 10 0 ^ts=35^ "MK1-S1 Ultrasonic Ruler"
ptl 40 180 "999 = out of range."
-- Quit button
pb 10 70 ^n=Quit^p=exitprog^
-- Setup the ultrasonic radar on port C.
uradar c1 c2
prog_start.
prog_loop =
-- main program loop
-- Display the distance reading in cm
ptl 40 120 ^ts=40^tc=blue^ "Distance /35 cm"
-- Wait 100ms
d100
prog_loop.
prog_stop =
ptl 10 0 ^ts=35^ "Bye"
prog_stop.