Time for action - click for the next slide

Our original slideshow contains a when right arrow key pressed control block to advance the screen. We will leave that control in place so that our slideshow still works when we share it on the Web.

Open your slideshow and save it as a new project so that you can feel free to experiment without altering the original project. If you don't have the slideshow, you can download mine from this book's web site at Packt Publishing.

  1. From the Control palette, add a when flag clicked block to the scripts area for the stage.
  2. Add a forever if control block.
  3. From the Sensing palette, add the sensor block as the input for the forever if block. Select button pressed from the drop-down list of options.
  4. Add a next background block to the forever if block.
    Time for action - click for the next slide
  5. Now, click the button on the PicoBoard. The slideshow should have advanced, but it advanced more than one screen. Try clicking slower. Ok, don't try too hard because it's nearly impossible to guarantee we can make one button click advance only one slide at a time.
  6. We can solve this timing problem with a broadcast message. From the control palette, add a broadcast next and wait block to the forever if block. Create a new broadcast named next.
  7. We need to receive the broadcast, so add a when I receive control block to the scripts area. Select next as the message.
  8. Move the next background block from the forever if block, and attach it to the when I receive block.
  9. Now, try the button click again.
Time for action - click for the next slide

Our button clicks are a bit more controlled with the broadcast block, but the slideshow still has a tendency to advance more than one slide at a time. As you think about how we can fix the timing problem, let's examine our script.

What just happened?

Even though our script behaved a bit wonkily, we got the general idea. The PicoBoard allowed us, the slideshow narrators, to be detached from the computer screen and the keyboard. Yet, we still controlled the pace of the show.

The key to this script was the forever if sensor button pressed block. The sensor reported a true or false value to measure the button click. If the button was pressed (true), then we broadcast the message to switch to the next background.

True or false values

To display the value of the button pressed sensor on the stage, click on the sensor block from the Sensing palette. Each time you click on the button, the sensor reports a true value.

Compare this to the other PicoBoard sensors that report a range of numbers. Either the button is pressed or not; we can't measure how hard we press the button.

In addition to the button sensor, the alligator clips that connect to the A, B, C, and D sensors also report a true or false value. Later in the chapter, we'll create a project to test whether or not the alligator clips are connected.

Let's get back to our slideshow and fix our timing problem.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.135.219.78