stan cartwright - 2017-03-10
;Read Sharp 2YOA21 distance sensor output with arduino uno
;and display distance in cm in a terminal.
#chip mega328p,16
#option Explicit
'USART settings
#define USART_BAUD_RATE 9600
#define USART_TX_BLOCKING
;
#define a2d portc.0 ; uno A0 pin
dir a2d in
dim a2dval as Integer
;
do
a2dval=readad10(a2d)
a2dval=6050/a2dval
if a2dval>=2 then
  a2dval=a2dval-2
end if
if a2dval<10 then
  a2dval=10
end if
if a2dval>80 then
  a2dval=80
end if
HSerPrint "Distance= "
HSerPrint a2dval
HSerPrint " CM"
HSerPrintCRLF
wait 100 ms;
loop