Shop OBEX P1 Docs P2 Docs Learn Events
Easy Newb Question — Parallax Forums

Easy Newb Question

DeskSquidDeskSquid Posts: 2
edited 2009-03-30 19:55 in BASIC Stamp
I need help, I'm just learning programming and pbasic and this is driving me nuts. I'm trying to get my program to adjust the calculations on my Ping))) sensor by recalculating the speed of sound based on air temperature and humidity. So far, I'm stuck on temp (just ordered humidity sensor), I got my program to correctly convert F to C but when it displays the speed of sound I get like 13,000m/s instead of ~340. I know it has something to do with the way the program is handling decimals/fractions.

What's happening?

'---[noparse][[/noparse] Constants ]
airFtemp CON 81 'manual input of air temp in fahrenheit
frac1 CON 36409 '5/9 * 65536 for temp conversion
frac2 CON 39321 '0.6 * 65536 for sound speed calc

'---[noparse][[/noparse] Variables ]
speed VAR Word
time VAR Word
cmDistance VAR Word
airCtemp VAR Word

'---[noparse][[/noparse] Mainroutine ]


DEBUG "TempF:", DEC airFtemp, CR
airCtemp = airFtemp - 32 ** frac1
DEBUG "TempC:", DEC airCtemp, CR
speed = frac2 * airCtemp
DEBUG "Speed:", DEC speed, CR

DO
PULSOUT 10, 5
PULSIN 10, 1, time
cmDistance = speed ** time
DEBUG "Distance:", DEC cmDistance, "cm", CR
PAUSE 100
LOOP


Thanks!

Comments

Sign In or Register to comment.