Not able to input decimal value
christineee
Posts: 17
I am trying to key in decimal value for my code but i cant seem to key in as when i click "run", there's an error message that reads:
I tried to put in " n DEC 0.034" at the top the declare variable, it does not help at all. I also read through the syntax and ref manual but there isnt any that tell me what extra coding i should put in.
Please help me!
I tried to put in " n DEC 0.034" at the top the declare variable, it does not help at all. I also read through the syntax and ref manual but there isnt any that tell me what extra coding i should put in.
Please help me!
Comments
To use fractions, you have to use some tricks. For instance, the Multiply High ( **) and Multiply Middle ( */) instructions will often let you do what you want. See the Stamp Syntax manual under the "Help" menu.
Also, you can often multiply a number like 1.234 by 1000, do the operations you need, then divide the answer by 1000 to get back.
Cheers,
The third parameter should be an integer specifying cycles in units of milliseconds (for the plain BS2). So if you want the PWM to last 34 milliseconds, just use 34.
For 70% PWM, use 0.7 * 256 = 179 as the second parameter.
I am trying to dim the LED to just 70% of its brightness.
The value 0.034 is in milliseconds.
This is my calculation:
Charge time = 5*R*C
=5*680*(0.01*10^-6)
=0.000034s = 0.034mS
Why are you using 256? Isnt it 254? I am confused.
The third parameter is the number of milliseconds you want the PWM to last. The Stamp does not do concurrent PWM, so if you are driving the LED directly, you may want the PWM to last several seconds. PWM can alternatively drive the LED via an analog circuit as described in the Stamp manual.
Ohh i see.. I guess i did some calculation errors.
Thanks!