Decimal to Integer conversion
g3cwi
Posts: 262
Hi all
New to this but I want to set a loop to repeat a number of times based on a calculation. The calculation produces a decimal value and the repeat command appears to need an integer. I tried "Round" but that did not help. Any ideas?
Thanks
Richard
New to this but I want to set a loop to repeat a number of times based on a calculation. The calculation produces a decimal value and the repeat command appears to need an integer. I tried "Round" but that did not help. Any ideas?
Thanks
Richard
Comments
If you could be more specific about what you what to do we probably better help. What calculation produces which decimal value?
It is an audio beeper and I want to use the number of cycles to determine the length of the beep accurately:
Cycles := ((1/Freq)*(Duration*1000)) 'Calculate the number of cycles for chosen duration
repeat Cycles
!outa[Pin] ' Toggle I/O pin
waitcnt(ClkFreq/Freq + cnt) ' Delay here sets the frequency
Cheers
Richard
Instead use:
You want to get in the habit of thinking of intermediate values.
Follow this link to learn how to post code in the forum.
That's a useful tip!
Regards
Richard
Your welcome.
By the way, welcome to the forum.
Duane