Using input from Switch to control a loop


Closed Thread
Results 1 to 10 of 10

Hybrid View

  1. #1
    Join Date
    Dec 2008
    Posts
    23

    Default Using input from Switch to control a loop

    How can I get input from a switch, ON/OFF, and use that to either enter a loop or exit a loop?

  2. #2
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Give this a try

    Code:
    switch var PortB.0
    
    main:
    if switch = 1 then loop ' enter the loop
    ' do some thing here . . . 
    goto main
    
    loop:
    if switch = 0 then main ' exit the loop
    . . . loop code does something . . . 
    
    goto loop
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  3. #3
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Code:
    WHILE Switch=1
            'put some code here
            WEND
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  4. #4
    Join Date
    Dec 2008
    Posts
    23


    Did you find this post helpful? Yes | No

    Default Declaring a variable as an input

    If I want switch to be linked to a pin, then how do I declare it before a loop to be an input?



    Is this code done for the PICBASIC assembly or a version of BASIC as the name implies?

  5. #5
    Join Date
    Dec 2008
    Posts
    23


    Did you find this post helpful? Yes | No

    Default Disregard reply above, did not see answer

    I did not see the first line, sorry, please disregard

  6. #6
    Join Date
    Dec 2008
    Posts
    23


    Did you find this post helpful? Yes | No

    Default Errors still with loop

    Can someone read below, I was told to do this and I am still getting the errors below the code, What am I doing wrong still?

    Thank you in advance.



    code below:
    ---------------
    switch var PortB.0

    main:

    if switch =1 then loop 'enter loop
    'forward
    high PORTB.7 'enable pin
    high PORTB.6
    low PORTB.5

    high PORTB.4
    low PORTB.3
    high PORTB.2 'enable pin

    goto main

    loop:
    if switch=0 then main 'exit the loop
    'backup
    high PORTB.7 'enable pin
    low PORTB.6 'stop this side
    low PORTB.5

    low PORTB.4 'reverse this side
    high PORTB.3
    high PORTB.2 'enable pin
    goto loop



    -------------------------------------
    errors recieved below:

    ERROR Line 13: ':' or '=' Expected (Token 'var') (Loop test2.pbc)
    ERROR Line 13: Illegal Character '.' (Loop test2.pbc)
    ERROR Line 17: Variable Expected (Token 'switch') (Loop test2.pbc)
    ERROR Line 19: Variable or Constant Expected (Token 'PORTB') (Loop test2.pbc)
    ERROR Line 19: Illegal Character '.' (Loop test2.pbc)
    ERROR Line 20: Variable or Constant Expected (Token 'PORTB') (Loop test2.pbc)
    ERROR Line 20: Illegal Character '.' (Loop test2.pbc)
    ERROR Line 21: Variable or Constant Expected (Token 'PORTB') (Loop test2.pbc)
    ERROR Line 21: Illegal Character '.' (Loop test2.pbc)
    ERROR Line 23: Variable or Constant Expected (Token 'PORTB') (Loop test2.pbc)
    ERROR Line 23: Illegal Character '.' (Loop test2.pbc)
    ERROR Line 24: Variable or Constant Expected (Token 'PORTB') (Loop test2.pbc)
    ERROR Line 24: Illegal Character '.' (Loop test2.pbc)
    ERROR Line 25: Variable or Constant Expected (Token 'PORTB') (Loop test2.pbc)
    ERROR Line 25: Illegal Character '.' (Loop test2.pbc)
    ERROR Line 30: Variable Expected (Token 'switch') (Loop test2.pbc)
    ERROR Line 32: Variable or Constant Expected (Token 'PORTB') (Loop test2.pbc)
    ERROR Line 32: Illegal Character '.' (Loop test2.pbc)
    ERROR Line 33: Variable or Constant Expected (Token 'PORTB') (Loop test2.pbc)
    ERROR Line 33: Illegal Character '.' (Loop test2.pbc)
    ERROR Line 34: Variable or Constant Expected (Token 'PORTB') (Loop test2.pbc)
    ERROR Line 34: Illegal Character '.' (Loop test2.pbc)
    ERROR Line 36: Variable or Constant Expected (Token 'PORTB') (Loop test2.pbc)
    ERROR Line 36: Illegal Character '.' (Loop test2.pbc)
    ERROR Line 37: Variable or Constant Expected (Token 'PORTB') (Loop test2.pbc)
    ERROR Line 37: Illegal Character '.' (Loop test2.pbc)
    ERROR Line 38: Variable or Constant Expected (Token 'PORTB') (Loop test2.pbc)
    ERROR Line 38: Illegal Character '.' (Loop test2.pbc)


    --------------------------------------

Similar Threads

  1. Controlsystem for compact sporting (clay shooting)
    By Fredrick in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 30th July 2009, 16:48
  2. Can't get COUNT to count
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 23rd March 2009, 23:14
  3. Serial Relays
    By tazntex in forum General
    Replies: 3
    Last Post: - 17th May 2007, 17:42
  4. Remote Control receiver - input source switching
    By jamie_s in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 16th October 2006, 21:20
  5. How can i control pic input pins order?
    By tanero in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 18th August 2005, 12:46

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