Home Chapter 8 BS2 Programming with a FOR NEXT loop

Site Search

GTranslate

Chinese (Simplified) French German Italian Portuguese Russian Spanish
BS2 Programming with a FOR NEXT loop


  1. These are the same outputs with the timing changing, as in the last experiment, except now we will be using a FOR NEXT LOOP. In the next chapter, we will be learning more about what you just programmed, and you will see the counting loop makes programming the LEDs even more fun
  2. Press the reset switch on the Board of Education.
  3.  

     

    What do you notice? _________________________________

     

  4. Enter the following program and run it on your current circuit.


  5. ‘{STAMP BS2}
          ' {$PBASIC 2.5}

    X var word

    DIRS = %11111111 ‘sets pins 0-7 as outputs only.

    For x = 0 to 1000 step 5 ‘counts from 0 to 1000 in increments of 5

    Outs = %01010101

    Pause x

    Outs = %10101010

    Pause x

    Next

    For x = 0 to 1000 step 10

    Outs = %01010101

    Pause x

    Outs = %10101010
    Pause x

    Next

    End

    Your turn

    Now create a custom pattern of your own, by manipulating the PAUSE and number associated with the FOR NEXT LOOP. You can get an intuitive feel for what the FOR NEXT LOOP does in this example.