PDA

View Full Version : Unsolved Help with Propeller programming.



chelleteng
04-08-2012, 09:13 AM
(In Public method)
repeat
(codes)
showBPM(DotYpos, 2)
(codes)
-----------------------------------------------------------------
PRI showBPM(num, counter) | count, bpm


gr.colorwidth(0,0)
gr.box(-128,-100,60,30)
if num > 0
count++
bpm := count - (count - ++counter)
showDEC(bpm)
else
showDEC(0)
------------------------------------------------------------------

***

[The showDEC method is just a function to display the numbers on the screen.]

Altered from Chip Gracey's Graphics Demo codes,
how do I increase the counter every time the num is more than 0? What I am currently getting on the display is constantly 3 only..
The program has only increment the counter once whenever the num is more than 0.
Any ideas? Thank you!

average joe
04-08-2012, 09:28 AM
I THINK it has to do with the way you are calling showBPM. Calling with the constant "2" will initialize the counter every time the method is run.


var long counter

(In Public method)
repeat
(codes)
counter := showBPM(DotYpos, counter)
(codes)
-----------------------------------------------------------------
PRI showBPM(num, c) | count, bpm


gr.colorwidth(0,0)
gr.box(-128,-100,60,30)
if num > 0
count++
bpm := count - (count - ++counter)
showDEC(bpm)
else
showDEC(0)

I'm unfamiliar with Chip's graphics demo codes so this is a stab in the dark. Something like this should get you going in the right direction hopefully!

T Chap
04-08-2012, 06:05 PM
Remember that local variables are not initialized to 0, they may be any random number until initialized. If you want to be sure the local vars are at 0 before doing any operations, set them to 0 yourself at the top of the code.

count := 0

average joe
04-08-2012, 06:44 PM
@T Chap Nice catch! I TOTALLY missed that!
@Chelleteng ..Quick hint. read this and pay attention to code format ;) http://forums.parallax.com/misc.php?do=bbcode

StefanL38
04-09-2012, 09:51 AM
Hi Cheteng,

to analyse what is going on I would insert debugcode into your actual code.
I mean sending the values of each variable involved into the calculations over a serial connection using pin 31,30 to see
what all the values are and how they change from loop to loop.
In this I would be more extensive than quick and short.

serial.str(string("count=")
serial.dec(count)

serial.str(string(" num=")
serial.dec(num)

serial.str(string("counter=")
serial.dec(counter)

serial.Tx(13)

for each and every single variable that is involved into the calculation

best regards
Stefan

chelleteng
04-09-2012, 11:05 AM
It works! :DDD

Thanks everyone for all your answers and help! :) Really appreciate it!
Thank youu!