Is thre a better way to code this..... reading 5 pings and converting the resu
Dgswaner
Posts: 795
This Code works but it seems a bit bulky and does take a bit of time to process. I'd appreciate any ideas on how to make it work better.
It reads 5 pings, converts the distance from to a letter A-I. which correlates to an Image on my PINK, visually indicating how close objects are.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"A complex design is the sign of an inferior designer." - Jamie Hyneman, Myth Buster
DGSwaner
It reads 5 pings, converts the distance from to a letter A-I. which correlates to an Image on my PINK, visually indicating how close objects are.
[b]PUB[/b] PINGs | pinkrange, val ,index range[noparse][[/noparse]0] := ping.Inches(PING_Pina) ' Get Range In Inches range := ping.Inches(PING_Pinb) ' Get Range In Inches range := ping.Inches(PING_Pinc) ' Get Range In Inches range := ping.Inches(PING_Pind) ' Get Range In Inches range := ping.Inches(PING_Pine) ' Get Range In Inches 'waitcnt(clkfreq / 10 + cnt) ' Pause 1/10 Second pointer:= 0 [b]repeat[/b] index [b]from[/b] 0 to 4 LCD.gotoxy(Index * 4, 0) ' Position Cursor LCD.decx(range[noparse][[/noparse]Index], 3) ' Print Inches [b]if[/b] Range[noparse][[/noparse]index] > range[noparse][[/noparse]pointer] Pointer := index [b]IF[/b] Range[noparse][[/noparse]index] > 80 Val := "I" [b]ELSEIF[/b] Range[noparse][[/noparse]index] > 32 Val := "H" [b]ELSEIF[/b] Range[noparse][[/noparse]index] > 28 Val := "G" [b]ELSEIF[/b] Range[noparse][[/noparse]index] > 24 Val := "F" [b]ELSEIF[/b] Range[noparse][[/noparse]index] > 20 Val := "E" [b]ELSEIF[/b] Range[noparse][[/noparse]index] > 16 Val := "D" [b]ELSEIF[/b] Range[noparse][[/noparse]index] > 12 Val := "C" [b]ELSEIF[/b] Range[noparse][[/noparse]index] > 8 Val := "B" [b]ELSEIF[/b] Range[noparse][[/noparse]index] > 4 Val := "A" XB.dec (Index + 1) XB.tx (Val)
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"A complex design is the sign of an inferior designer." - Jamie Hyneman, Myth Buster
DGSwaner
Comments
dat
len byte 4,8,12,16,20,24,28,32,80,65535
repeat i from 0 to 9
if range[noparse][[/noparse]index] < len
quit
val := "A" + i - 1
I haven't tested it, but I would think that you could simplify all of your elseif to something like this...
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
Thanks I'll give that a try when I get home.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"A complex design is the sign of an inferior designer." - Jamie Hyneman, Myth Buster
DGSwaner