Shop OBEX P1 Docs P2 Docs Learn Events
DEBUG function DEC — Parallax Forums

DEBUG function DEC

jackass867jackass867 Posts: 1
edited 2009-12-08 17:04 in BASIC Stamp
alright heres my·problem I have an input var·byte and then I would like to display the decimal value. I've had no problem doing this, however I would then like to use that decimal value and perform some mathematical operations on it. I've figured out some roundabout ways to do this, but as the computations become more involved it has become nearly impossible. So what I am wondering is if there is any way to use that decimal value outside of the debug command. If anyone has any ideas please let me know. here is a sample of my code


· LOW ADC_cs··························· ' Set Clock Select Low - enable
· SHIFTIN ADC_data, ADC_clk, MSBPOST, [noparse][[/noparse]ADC_value\9]· ' Read value of ADC
· HIGH ADC_cs·························· ' Set Clock Select High - disable
· DEBUG CR, "ADC: ", DEC ADC_value····· ' Print return carriage, and ADC value
· DEBUG CR,"Volt=", DEC ((ADC_value*5)/255),".",····· ' voltage corresponding to ADC_value
· DEC (((ADC_value*5)//255)*100)/255,"V"
· DEBUG CR,"GF=", DEC ((ADC_value*5*10)/255),".",····· ' voltage corresponding to ADC_value
· DEC (((ADC_value*5*10)//255)*100)/255,"m/s^2"

thanks for the help!

Comments

  • Tracy AllenTracy Allen Posts: 6,662
    edited 2009-12-08 17:04
    Convert it to millivolts. The */ operator is your friend:
    mV = ADC_value */ 5000
    The factor 5000 comes from 5000mV per 256 counts. See the Stamp manual and also this link for Stamp math.

    Once the value is in mV, display it:
    DEBUG DEC mV/1000, ".", DEC3 mV, CR ' x.xxx
    or do additional math.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
Sign In or Register to comment.