IF..THEN syntax


Results 1 to 40 of 53

Thread: IF..THEN syntax

Threaded View

  1. #8
    Join Date
    Oct 2006
    Posts
    32


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by scaenix View Post

    'Read Cds cell #1 on port b line 1
    'Read Cds cell #2 on port b line 7
    v1 var byte 'Variable v1 holds Cds #1 information
    v2 var byte 'Variable v2 holds Cds #2 information
    v3 var byte 'Variable for calculation
    s1 var byte 'Variable s1 holds servomotor #1 pulse width info
    s2 VAR word 'variable for random function
    rv var byte 'variable rv holds the range value
    s1 = 150 'initialize steering servomotor facing forward
    rv = 10 'Adjust as needed for operation
    ct var byte 'counter


    start:
    pot portb.2,255,v1
    pot portb.3,255,v2

    'Check bumper switch "Did I hit something?"
    if porta.0 = 0 then avoid 'Hit obstacle go into avoid mode
    'Is it sleepy time?
    if v1 <= 230 then skp 'Is it dark enough to sleep?
    if v2 > 230 then slp 'Yes

    'Is it too bright to see?
    skp:
    if v1 >= 12 then skip2
    if v2 < 12 then avoid

    'Which way do I go?
    skip2:
    if v1 = v2 then straight
    if v1 > v2 then greater
    if v1 < v2 then lesser

    straight:
    pulsout portb.6, s1
    pulsout portb.7, 157
    goto start

    greater:
    v3 = v1 - v2
    if v3 > rv then right
    goto straight

    lesser:
    v3 = v2 - v1
    if v3 > rv then left
    goto straight

    right:
    s1 = s1 + 1
    if s1 > 225 then s1 = 225
    pulsout portb.6, s1
    pulsout portb.7, 165
    goto start
    left:
    s1 = s1 - 1
    if s1 < 65 then s1 = 65
    pulsout portb.6, s1
    pulsout portb.7, 165
    goto start

    slp:
    pulsout portb.6, s1
    pulsout portb.7, 167
    goto start

    avoid:
    random s2
    s1 = s2 / 256
    if s1 < 65 then s1 = 65
    if s1 > 225 then s1 = 225
    for ct = 1 to 125
    pulsout portb.6, s1
    pulsout portb.7, 177
    pause 18
    next ct

    s1 = 150

    goto start

    I've quoted the code I've posted in one of the previous replies. the program is supposed to make the servomotor #1, which is connected to RB7 stop when in total darkness. I'm confused why the motor still continues on turning even if it is supposed to stop. Please anyone enlighten me on this. Thanks very much!
    Last edited by scaenix; - 19th February 2007 at 09:09.

Similar Threads

  1. Endless supply of 'syntax error's.
    By BitHead in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 14th December 2009, 21:21
  2. Replies: 0
    Last Post: - 1st September 2008, 08:03
  3. Math operations & Syntax?
    By kevj in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 23rd February 2008, 02:40
  4. Need help with I2C syntax problem?
    By Michael Wakileh in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 19th July 2007, 20:11
  5. Syntax error PIC16F684
    By milestag in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 21st September 2005, 19:54

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