newbie Q - edge detection?


Results 1 to 16 of 16

Threaded View

  1. #9
    Join Date
    May 2004
    Location
    New England
    Posts
    164


    Did you find this post helpful? Yes | No

    Default

    I'll try 2 & 3...

    Code:
    For CounterA = 1 To 20   ; "CounterA" keeps track of the loop count for the first FOR/NEXT loop
    
        For CounterB = 1 To 10   ; "CounterB" keeps track of the loop count for the second FOR/NEXT loop
            Pause 1
        Next CounterB
        
        Pause 1
    Next CounterA
    What happens is...

    The first loop begins (call it the "A" loop), and "CounterA" is automatically set to '1' at its start.

    The next line of code starts up a second loop (the "B" loop), setting "CounterB" to '1' at the start of that loop.

    Since the first "Next" command is the "Next CounterB" line of code, the "B" loop will now continue for 10 iterations until it is finished.

    We now hit the "Next CounterA" line - we go back to the beginning of "A" loop, the "CounterA" variable is incremented by 1, and then we restart the "B" loop again, finishing it before again going back to the "A" loop.

    The "B" loop runs start to finish each time through the "A" loop. The "B" loop will be run a total of 20 times, for a total of 200 cycles (10 cycles per "B" loop, times 20 "A" loops).

    While a FOR/NEXT loop is running, you want to make sure your code does not alter the "Counter" variable that is used to store the loop count (unless you are intentionaly changing it!).
    Before a FOR/NEXT loop starts, or once the loop is finished, the variable can be used freely for other purposes in your code.


    On #3... Give the variables names that mean something to you - instead of x, y, z, etc, use RedLED, GreenLED (pin variables), EventCount, PumpStatus, etc. Try not to use abbreviations, as you'll forget what they mean after a short time (I always do anyways).


    Clear as mud? :-)

    Arch
    Last edited by Archilochus; - 1st October 2006 at 17:04.
    "Data sheets? I ain't got no data sheets. I don't need no data sheets. I don't have to read any stinking data sheets!"

Similar Threads

  1. mS Timer
    By whmeade10 in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 8th September 2020, 12:12
  2. Newbie making an ignition timer
    By ChrisHelvey in forum mel PIC BASIC Pro
    Replies: 17
    Last Post: - 5th August 2012, 17:45
  3. RC Servo decoding/encoding using 12F683
    By ScaleRobotics in forum Code Examples
    Replies: 13
    Last Post: - 14th September 2010, 00:49
  4. Phase failure detection
    By ardhuru in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 9th January 2007, 00:53
  5. Auto Baud Rate Detection
    By mytekcontrols in forum Serial
    Replies: 10
    Last Post: - 31st October 2005, 02:17

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts