Inicio Foros 2019 Robot Help Toggle button

Etiquetado: , ,

Mostrando 1 respuesta al debate
  • Autor
    Publicaciones
    • #719
      brodlondaniel
      Participante

      I am trying to use a button to turn on and off a motor, but when i tap the button it sends off about 4-5 triggers in quick succession. How do i add in a delay timer using BLOCKS

    • #720
      noahandrews
      Participante

      There are a couple of ways you can do a delay in Blocks.

      Under “LinearOpMode”, there is a sleep block that will pause the program for a certain number of milliseconds. You shouldn’t use this in the middle of your robot loop, as the robot will stop responding to gamepad input.

      Under “Utilities -> Time -> ElapsedTime” you will find blocks that will let you keep track of the passage of time by creating a new ElapsedTime and assigning it to a variable.

      However, the easiest and best way to do what you’re looking to do is not to use a delay or timer at all. What you really want is to store the state of the button as of the PREVIOUS loop. To do this, update the variable as the last action in the loop.

      Now that you have a variable that has the state of the button as of the previous loop, you can use it to decide whether or not you should ignore the button press. If the button was previously NOT pressed AND is currently pressed, then proceed as if it was pressed.

      The key thing to realize is that nothing in Blocks is a “trigger”. The blocks merely tell you what the current state is as of the time they are executed.

      I hope that helps, please reach out if you need more clarification.

Mostrando 1 respuesta al debate
  • Debes estar registrado para responder a este debate.
es_MXES
en_USEN fr_FRFR es_MXES
Abrir la barra de herramientas