Shop OBEX P1 Docs P2 Docs Learn Events
Troubles with For-Loops (have the prop this) — Parallax Forums

Troubles with For-Loops (have the prop this)

nomadnomad Posts: 276
edited 2009-04-23 06:56 in Propeller 1
hi.
i have little problem,
i have a BS2-programm for controlling servos
(from my bs2-code)
but i see that spin have no For-Loops

how can i do this with spin:
in the ObjectExchange i find nothing (BS2)

thanks for help, tipps and hints
regards
nomad

a bs2-code snippet:
runningRoll:

   IF(newRollPulses > oldRollPulses) THEN

       FOR pulses = oldRollPulses TO newRollPulses + steps

           DEBUG "Pulses:", DEC pulses, CR

           PULSOUT RollServo13, pulses

          PAUSE 20

       NEXT

       oldRollPulses = newRollPulses

       DEBUG "5\r",CR

    

   IF(newRollPulses < oldRollPulses) THEN

       FOR pulses = oldRollPulses TO newRollPulses - steps

         ' DEBUG "Pulses: ", DEC pulses, CR

          PULSOUT RollServo13, pulses

          PAUSE 20

       NEXT

       oldRollPulses = newRollPulses

       DEBUG "5\r",CR

   

Comments

  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2009-04-22 15:15
    Spin overloads its repeat statement with for-loop capability. In your case it would be:

    [b]repeat[/b] pulses [b]from[/b] oldRollPulses [b]to[/b] newRollPulses + steps
       ...
    
    
    


    There's no terminal equivalent to NEXT, since all nesting is indicated with indentation.

    -Phil
  • Mike GreenMike Green Posts: 23,101
    edited 2009-04-22 15:17
    1) Spin has the REPEAT statement which replaces the FOR / NEXT statement and the DO / LOOP statement. Read the description in the manual.

    2) Spin uses included objects to provide functionality. Some are included with the Propeller Tool and others can be downloaded from the Propeller Object Exchange (see the link at the bottom of the main Parallax webpage). "Servo32v3" is included with the Propeller Tool and there's a demo program also included that illustrates its use. It takes care of all the servo pulse processing for you and works somewhat like the Parallax Servo Controller.

    3) If you're doing much in the way of converting Stamp programs to the Propeller, look at the BS2_Functions object in the Object Exchange. It provides subroutines for much of the functionality of the Stamp's I/O statements.
  • nomadnomad Posts: 276
    edited 2009-04-23 06:56
    hi phil hi mike
    thank you for your help and the prompt answer.
    i take it.
    regards
    nomad
Sign In or Register to comment.