Triggers

Now we will start working with multiple start commands. We will use our code from lesson 1, but we will add in a kill button so that we can easily stop our code. To do so we will start with our code from lesson 1.

Screenshot (169)

Then we will get a “when space key pressed” starting block and drag it next to our lesson 1 code.

We will add in a Screenshot (170)  below the Screenshot (171)  block, so that we can have it be our kill button that will stop our CoDrone in case there is a problem. But we will have a problem, if we press the kill button, our other code is still running, so it will stop, and then go again. To fix this we will use a new block, Screenshot (172). This block will stop all other running programs, this way our autonomous code will stop running, and then we can send the stop command to the CoDrone.

RB trigger 1

Try it Out: Try to fly your CoDrone and then while it is flying stop it with our kill code.

Challenge: Create a program that can move in a square. Each side of the square could be a different key (example the first side (forward) would be key 1, the second side (right) would be 2, ect.). You will need to have one that will take off and one that would land (our kill would work for that).

Hints:

  • When the button is pressed have it move and stop on its own.
  • You will need one button for each direction (forward, right, backward, left) plus takeoff and stop/land.