GOTO main or RETURN - Question


Results 1 to 6 of 6

Threaded View

  1. #2
    Join Date
    Dec 2005
    Posts
    46


    Did you find this post helpful? Yes | No

    Default

    I'm a rookie, but I think using subs will work like this. Subs have to be after the "end" statement.
    Code:
      main
    if switch1 = 1 then GoSub servocenter 
    if switch1 = 0 then low led1
    if switch2 = 1 then GoSub servoright
    if switch2 = 0 then low led2
    if switch3 = 1 then GoSubservoleft
    if switch3 = 0 then low led3
    if switch4 = 1 then high led4
    if switch4 = 0 then low led4
    goto main
    
    end
    
    servocenter:
    serout lcd1, t9600, [$fe,1," center"]
    high led1
    pulsout servo1, 150
    pause 200
    Return
    
    servoright:
    serout lcd1, t9600, [$fe,1," right"]
    high led2
    pulsout servo1, 100
    pause 200
    Return
    
    servoleft:
    serout lcd1, t9600, [$fe,1," left"]
    high led3
    pulsout servo1, 200
    pause 200
    Return
    OR, you could move each of the items below each if statement.

    Code:
      main
    if switch1 = 1 then GoSub 'servocenter 
    serout lcd1, t9600, [$fe,1," center"]
    high led1
    pulsout servo1, 150
    pause 200
    endif
    
    if switch1 = 0 then low led1
    
    if switch2 = 1 then GoSub 'servoright
    serout lcd1, t9600, [$fe,1," right"]
    high led2
    pulsout servo1, 100
    pause 200
    endif
    
    if switch2 = 0 then low led2
    
    if switch3 = 1 then GoSub 'servoleft
    serout lcd1, t9600, [$fe,1," left"]
    high led3
    pulsout servo1, 200
    pause 200
    endif
    
    if switch3 = 0 then low led3
    if switch4 = 1 then high led4
    if switch4 = 0 then low led4
    goto main
    Last edited by g-hoot; - 31st January 2009 at 15:42.

Similar Threads

  1. Delayed output 10 secs
    By lilimike in forum mel PIC BASIC Pro
    Replies: 37
    Last Post: - 14th October 2011, 06:28
  2. Making a menu
    By chrisshortys in forum mel PIC BASIC Pro
    Replies: 36
    Last Post: - 12th November 2008, 19:54
  3. Replies: 14
    Last Post: - 26th September 2007, 05:41
  4. Output PIC module
    By freelancebee in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 12th September 2005, 20:10
  5. Can anyone help a beginner in a struggle?
    By douglasjam in forum mel PIC BASIC
    Replies: 1
    Last Post: - 5th May 2005, 23:29

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