Shop OBEX P1 Docs P2 Docs Learn Events
Help with Propeller programming. — Parallax Forums

Help with Propeller programming.

chelletengchelleteng Posts: 29
edited 2012-04-09 04:05 in Propeller 1
(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!

Comments

  • average joeaverage joe Posts: 795
    edited 2012-04-08 02:28
    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 ChapT Chap Posts: 4,223
    edited 2012-04-08 11:05
    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 joeaverage joe Posts: 795
    edited 2012-04-08 11:44
    @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
  • StefanL38StefanL38 Posts: 2,292
    edited 2012-04-09 02:51
    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
  • chelletengchelleteng Posts: 29
    edited 2012-04-09 04:05
    It works! :DDD

    Thanks everyone for all your answers and help! :) Really appreciate it!
    Thank youu!
Sign In or Register to comment.