Author Topic: Problem with BUTTON command in PBASIC  (Read 2195 times)

0 Members and 1 Guest are viewing this topic.

Offline deathwing61Topic starter

  • Beginner
  • *
  • Posts: 1
  • Helpful? 0
Problem with BUTTON command in PBASIC
« on: September 03, 2008, 07:23:06 AM »
following is my code. when a whisker button is pressed it runs the segment 10-20 times i only need it once. any idea what's causing this?




Code: [Select]
' {$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

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,658
  • Helpful? 169
    • Society of Robots
Re: Problem with BUTTON command in PBASIC
« Reply #1 on: September 04, 2008, 07:27:02 PM »
Quote
when a whisker button is pressed it runs the segment 10-20 times i only need it once
This is because of something called 'bouncing'. Basically, even though you push it once, in reality it bounces really really fast. The microcontroller counts all of the bounces.

To fix it, just add a small "do nothing" delay like .25ms after the button push in your code.

 


Get Your Ad Here