Shop OBEX P1 Docs P2 Docs Learn Events
A PBasic routine How would you write it to do the same thing in Spin — Parallax Forums

A PBasic routine How would you write it to do the same thing in Spin

sam_sam_samsam_sam_sam Posts: 2,286
edited 2010-04-27 21:46 in Propeller 1
Here is the routine
' {$STAMP BS2}
' {$PBASIC 2.5}
 
 
chg    VAR    IN0
cntr   VAR    Byte
 
 
' The table is   [color=red]IF Chg = 1 Then Loop = 100[/color]  [color=blue]If Chg = 0 THEN Loops = 0     [/color]
 

DO

cntr = cntr + 1 * Chg
IF (cntr = 100) THEN EXIT    ' Exit or to a subroutine
 
LOOP


Thanks to anyone that can help

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·Now wanting to learn Spin· Thanks for any·idea.gif·that you may have and all of your time finding them smile.gif

·
·
·
·
Sam

Post Edited (sam_sam_sam) : 4/27/2010 2:03:36 PM GMT

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2010-04-27 14:46
    var byte cntr
    
    


    repeat
       cntr := cntr + ina[noparse][[/noparse] 0 ]
       if cntr == 100
          exit
    
    
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2010-04-27 14:50
    Thanks Mike Green

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·Now wanting to learn Spin· Thanks for any·idea.gif·that you may have and all of your time finding them smile.gif

    ·
    ·
    ·
    ·
    Sam
  • John AbshierJohn Abshier Posts: 1,116
    edited 2010-04-27 14:56
    con
    input_pin = 3
    var
    long ctr
    Pub main
    dira[noparse][[/noparse]input_pin]~
    repeat until ctr == 100
    ctr += ina[noparse][[/noparse]input_pin]

    John Abshier
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2010-04-27 16:26
    What is need to make this an Object

    '' File: ButtonTimeOut.spin
     
    
    var
    long ctr
    Pub main  (pin)
    dira[noparse][[/noparse]pin]~
    repeat until ctr == 100
    ctr += ina[noparse][[/noparse]pin]
    
    

    I want to Thank John Abshier for his help

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·Now wanting to learn Spin· Thanks for any·idea.gif·that you may have and all of your time finding them smile.gif

    ·
    ·
    ·
    ·
    Sam
  • JonnyMacJonnyMac Posts: 9,208
    edited 2010-04-27 16:53
    I think Sam's original code should translate to

    repeat
      ctr := ++ctr * ina[noparse][[/noparse]Chg]
      if (ctr == 100)
        exit
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon McPhalen
    Hollywood, CA
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2010-04-27 18:41
    I would like to add this to it as well in the same Object if it can be done
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
     
     
    chg    VAR    IN0
    cntr   VAR    Byte
     
     
    ' The table is   [color=red]IF Chg = 0 Then Loop = 100[/color]  [color=blue]If Chg = 1 THEN Loops = 0     [/color]
     
    
    DO
    
    cntr = cntr + 1 * (1 - Chg)
        IF (cntr = 100) THEN EXIT    ' Exit or to a subroutine
     
     
    'I want to be able call up which one I want to use 
     
     
     
    ' The table is   [color=red]IF Chg = 1 Then Loop = 100[/color]  [color=blue]If Chg = 0 THEN Loops = 0     [/color]
     
    
     
    
    cntr = cntr + 1 * Chg
    IF (cntr = 100) THEN EXIT    ' Exit or to a subroutine
    
     
    LOOP
    




    Jonny Mac

    Thank you for your reply

    How ever EXIT is not a commmand in Spin· what command would be close to a EXIT command that is used·in PBasic

    What I want to do·is to write a routine in Spin as a Oject·that will do the same thing as it dose in a·PBasic routine
    with a Debug so·I can see the state change and see the counter going up in this object

    ·

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·Now wanting to learn Spin· Thanks for any·idea.gif·that you may have and all of your time finding them smile.gif

    ·
    ·
    ·
    ·
    Sam

    Post Edited (sam_sam_sam) : 4/27/2010 7:15:34 PM GMT
  • Shawn LoweShawn Lowe Posts: 635
    edited 2010-04-27 21:01
    S^3,
    I think you just go back one indentation:

    repeat
      ctr := ++ctr * ina[noparse][[/noparse]Chg]
         if (ctr == 100)
    
    next instruction...
    
    

    I'm not sure though

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Shawn Lowe


    When all else fails.....procrastinate!
  • AribaAriba Posts: 2,690
    edited 2010-04-27 21:37
    exit = quit in Spin

    Here an example with a subroutine that has a parameter mode, which switches btween first and second version.
    CON
      chg  = 0
    
    VAR
      byte  cntr
    
    PUB main
      count(0)
      count(1)
    
    PUB count(mode)
      if mode == 0
        repeat
          cntr := cntr + ina[noparse][[/noparse]chg]
          if cntr == 100
            quit
      else
        repeat
          cntr := cntr + 1 - ina[noparse][[/noparse]chg]
          if cntr == 100
            quit
    
    



    Andy
  • AribaAriba Posts: 2,690
    edited 2010-04-27 21:46
    And some variations of the count repeat loop
      repeat while cntr < 100
        cntr += ina[noparse][[/noparse]chg]
    
    
      repeat
        cntr += 1 - ina[noparse][[/noparse]chg]
      until cntr == 100
    
    
Sign In or Register to comment.