Shop OBEX P1 Docs P2 Docs Learn Events
problems with the BUTTON command — Parallax Forums

problems with the BUTTON command

Deathwing61Deathwing61 Posts: 5
edited 2008-09-08 17:54 in Learn with BlocklyProp
following is my code. when a whisker comes in contact with something it runs the segment 10-20 times. any idea what's causing this?



' {$STAMP BS2}
' {$PBASIC 2.5}
' My first Robot
' I shall call him... Jean-Luc

' Go forward untill you feel something


TOP:                      'lable

  HIGH 0                  'left wheel forward
  LOW 1
  HIGH 2                  'right wheel forward
  LOW 3

  LeftButton VAR Byte
  LeftButton = 0

  RightButton VAR Byte
  RightButton = 0

  BUTTON 4, 1, 255, 0, LeftButton, 1, LeftWhisker

  BUTTON 5, 1, 255, 0, RightButton, 1, RightWhisker

GOTO TOP

LeftWhisker:               'If left whisker contacts do this

  LOW 0                   'left wheel reverse
  HIGH 1
  LOW 2                   'right wheel reverse
  HIGH 3
  PAUSE 500              'reverse .5 seconds

  LOW 0                   'left wheel stop
  LOW 1
  LOW 2                   'right wheel reverse
  HIGH 3
  PAUSE 500               'back/turn right .5 seconds

  GOTO TOP 'go back to program

RightWhisker:             'If Right whisker contacts do this

  LOW 0                   'left wheel reverse
  HIGH 1
  LOW 2                   'right wheel reverse
  HIGH 3
  PAUSE 500              'reverse .5 seconds

  LOW 0                   'left wheel reverse
  HIGH 1
  LOW 2                   'right wheel stop
  LOW 3
  PAUSE 500               'back/turn left .5 seconds

  GOTO TOP 'go back to program

Post Edited (Deathwing61) : 9/3/2008 3:41:49 AM GMT

Comments

  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2008-09-06 03:05
    Deathwing61

    First let me say Welcome to the Parallax Forum

    One Thing you need·do at very top of· your code is to define your PIN·VAR and CON at the top·

    One thing to be care full of is where you put some commands it dose make a deferents·where you put them in your routines



    TOP:······················'lable

    ··HIGH·0··················'left·wheel·forward
    ··LOW·1
    ··HIGH·2··················'right·wheel·forward
    ··LOW·3

    ··LeftButton·VAR·Byte
    ··LeftButton·=·0····· By putting this here you are forcing the LeftButton·not to rountine to be·running ·all the time

    ··RightButton·VAR·Byte
    ··RightButton·=·0··· By putting this here you are forcing the RightButton·not to· rountine to be·running·all··the time


    ··BUTTON·4,·1,·255,·0,·LeftButton,·1,·LeftWhisker

    ··BUTTON·5,·1,·255,·0,·RightButton,·1,·RightWhisker



    This makes it a lot·easier to read and follow· something like this



    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    ' My first Robot
    ' I shall call him... Jean-Luc

    ' Go forward untill you feel something

    LeftWheel·········· PIN··········· 0
    LeftWheelA········· PIN··········· 1
    RightWheel········· PIN··········· 2
    RightWheelA········ PIN··········· 3



    LeftButton·········· VAR·········· Byte
    RightButton········· VAR·········· Byte


    Timer··············· CON·········· 500

    ·' By putting it here you only force it not to run·the·routine once

    LeftButton = 0
    RightButton = 0


    TOP:······························· 'lable

    ·BUTTON 4, 1, 255, 0, LeftButton, 1, LeftWhisker
    ·BUTTON 5, 1, 255, 0, RightButton, 1, RightWhisker


    · HIGH leftwheel·················· 'left wheel forward
    · LOW leftwheelA
    · HIGH rightwheel················· 'right wheel forward
    · LOW rightwheelA

    GOTO TOP




    LeftWhisker:····················· 'If left whisker contacts do this

    · LOW LeftWheel··················· 'left wheel reverse
    · HIGH LeftWheelA
    · LOW· RightWheel················· 'right wheel reverse
    · HIGH RightWheelA


    · PAUSE· Timer····················· 'reverse .5 seconds


    · LOW LeftWheel··················· 'left wheel stop
    · LOW LeftWheelA
    · LOW RightWheel··················· 'right wheel reverse
    · HIGH RightWheelA

    · PAUSE· Timer······················ 'back/turn right .5 seconds


    · GOTO TOP·························· 'go back to program



    RightWhisker:························ 'If Right whisker contacts do this

    · LOW LeftWheel······················ 'left wheel reverse
    · HIGH LeftWheelA
    · LOW· RightWheel···················· 'right wheel reverse
    · HIGH RightWheelA


    · PAUSE Timer························· 'reverse .5 seconds


    · LOW LeftWheel······················· 'left wheel reverse
    · HIGH LeftWheelA
    · LOW RightWheel······················ 'right wheel stop
    · LOW RightWheelA


    · PAUSE Timer························· 'back/turn left .5 seconds


    · GOTO TOP···························· 'go back to program


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ··Thanks for any·idea.gif·that you may have and all of your time finding them

    ·
    ·
    ·
    ·
    Sam

    Post Edited (sam_sam_sam) : 9/6/2008 3:49:59 AM GMT
  • MikerocontrollerMikerocontroller Posts: 310
    edited 2008-09-06 03:39
    ·· I'm curious..what are you using to control the motors?





    Helicopter Pilot: "I'm lost where am I?"

    Microsoft:"You're in a helicopter"
  • Deathwing61Deathwing61 Posts: 5
    edited 2008-09-08 17:54
    thanks i'll try it.
    i'm using a quad half h-bridge ic
Sign In or Register to comment.