Lesson 9 – Fun with Lights

Lesson Description

In this lesson, you will learn: how to to get the state of the button in PictoBlox, how to make a lamp with Quarky and display a custom pattern on the matrix by making a script to display a Traffic Light.

QUARKY SWITCHES

Quarky has 2 tactile switches or buttons which allow Quarky to take input from the user.

You can get the state of the button in PictoBlox using is button () pressed? block. The block reports 1 when the switch is pressed and 0 when the switch is not pressed.

ACTIVITY 1: LAMP WITH QUARKY

Let’s make a lamp with Quarky. The logic is simple – if we press the left switch, L, the lamp should turn OFF. If we press the right switch, R, the lamp should turn ON.

CODING STEPS

Follow the steps below:

  1. Create a New file in PictoBlox App.
  2. Connect Quarky to PictoBlox.
  3. Go to the Sensors palette and add a is button () pressed? block into the scripting area. The button, L, is set as the default option.
  4. To check if Lis pressed, we’ll use an if Go to the Control palette and drop an if block into the scripting area. Drop the is button () pressed? block in the white space of the if block.
  5. If L is pressed, then, according to our logic, the LEDs should turn OFF. Therefore, go to the Displaypalette and drop a clear screen block inside the if block.
  6. However, if R is pressed, then the LEDs should turn ON. Therefore, add another if block below the first one and drop a is button () pressed? block in the white space.
  7. Then, go to the Displaypalette and drop display matrix as () block inside the if block, and set all the LEDs as white.
  8. Add a forever block around the entire script.
  9. To add the finishing touch, add a when flag clicked block from the Events palette above the forever block.
  1. Finally, click the green flag to run the script. Press the L switch to turn ON the lights and R to turn OFF the lights.
  2. Save the file as Lamp.

ACTIVITY 2: TRAFFIC LIGHT WITH QUARKY

In this activity, we’re going to see how we can display a custom pattern on the matrix by making a script to display a Traffic Light.

CODING STEPS

Follow the steps below:

  1. Create a New file in PictoBlox App.
  2. Connect Quarky to PictoBlox.
  3. Drag and drop a when flag clicked block into the scripting area from the Events palette.
  4. Below the when flag clicked block, add the set display brightness to () block from Display In the space write 15.
  5. Add a forever block from the Control palette below the set display brightness to () block.
  6. Inside the forever block, add a display matrix as () block from the Display Fill the matrix with red color.
  7. Add the wait () seconds block under the display matrix as () block and set the waiting time as 5 seconds.
  8. Go to the Display palette and add a display () with () block into the scripting area. In the space, enter 2. Then, set the color of the LED to yellow-color from the drop-down and this will display number 2 in yellow color.
  9. Add another wait () seconds block under the display () with () block and set the waiting time as 1 second.
  10. Now add another display () with () block below the wait () seconds In the space, enter 1. Then, set the color of the LED to yellow-color from the drop-down and this will display number 1 in yellow color.
  11. Again, add another wait () seconds block under the display () with ()block and set the waiting time as second.
  12. Right-click on the display matrix as () block and duplicate the code. Set the color as Green in display matrix as () block.
  13. The code is complete. Click on the green flag and test the code. You will see Quarky running like a Traffic Light.
  14. Save the file as Traffic Light.

Table of Contents