Announcement

Collapse
No announcement yet.

Programming Triggers & Bumpers

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Programming Triggers & Bumpers

    Hi,

    In app inventor, how are bumpers and triggers programmed? Since the buttons and dpad return a boolean value, a simple, if, else if, and else statement can be used to control a motor with these buttons. I have read something about them returning a digital or analog value which changes when pressed. Could someone please explain and put some sample code using triggers & bumpers? Thanks.

  • #2
    I mean how to program the triggers. Is it correct that you initialize a variable to 0, and then set that variable to right/left trigger. Then, if that variable is 1 because the trigger is pressed. move the motor or servo? Could someone please put some sample code so I can understand?

    Comment


    • #3
      Here is some example code. I don't think you need to use variables unless your control code becomes much more complex. Here, pressing the left bumper moves a motor left and pressing the right bumper moves it right. Holding down the A button and using the right trigger moves another motor in one direction (at higher power the more the trigger is pressed), and not holding A moves it in the other direction (also with power proportional to the amount the trigger is pressed). The bumpers are just like other buttons in that they have Boolean values, but the triggers give a value from 0 to 1 depending on how much they are pressed.

      Comment


      • #4
        Thanks for the sample code! I still don't understand how to program the triggers. In your sample, you have to press a on gameapad 1 for some reason. Could you please write a sample code where if the right trigger is pressed, then set a motor to power 1?

        Comment


        • #5
          Originally posted by clock View Post
          Thanks for the sample code! I still don't understand how to program the triggers. In your sample, you have to press a on gameapad 1 for some reason. Could you please write a sample code where if the right trigger is pressed, then set a motor to power 1?
          The value of the trigger is a number between 0 and 1. If you want to use the trigger like a button, you can check to see whether the value is greater than 0.5:

          Comment


          • #6
            Thanks for your help! I appreciate it.

            Comment


            • #7
              Originally posted by GearTicks View Post
              The value of the trigger is a number between 0 and 1. If you want to use the trigger like a button, you can check to see whether the value is greater than 0.5:
              Can this also be done with servo motors?

              Comment


              • #8
                Originally posted by RoboticsFun View Post
                Can this also be done with servo motors?
                Sure, using the triggers as buttons to get Boolean values has nothing to do with whether you are using motors or servos.

                Comment

                Working...
                X