Program Quarky Tactile Switches with Pictoblox

Description
Learn how to program Quarky tactile switches with Pictoblox. This includes configuring the switches in Quarky Settings, and programming them in both Stage Mode and Upload Mode with Pictoblox blocks and functions.

Introduction

Quarky has two tactile switches on the top side. The Switch is labeled L (Left Switch) and R (Right Switch) as shown below.

The switches can be used as game input and many other applications.

Fruit-Catcher-Game

How Tactile Switch Works

Pressing the left and right switches on Quarky sends analog values to PictoBlox. Pictoblox checks the range in which this value falls and based on that it declares if the left or right push button is pressed.

If push buttons are not working on Quarky, you can check the same in Quarky Setting: https://ai.thestempedia.com/docs/quarky/quarky-toubleshooting/quarky-settings-in-pictoblox/

You can configure the switches using these options.

  1. Push Botton Analog Values: You can check if the pushbutton on Quarky is working properly using this option. Click on the Get button, this will start filling the box with the analog values of the pushbutton. If the value is shown as just -, it means the board is not responding (check if the firmware is uploaded on Quarky properly), if the value is stuck at 0, it may suggest a problem with the hardware.
  2. Push Button L & R-Value: The analog values may differ between boards and the user may wish to change this range for L and R push buttons. You can do the same using this option. Add the min and the max analog reading and click on Set Range.

Block Coding

In PictoBlox, you have the following blocks available for the tactile switches:

  1. when button () pressed: The block is a hat block and starts the execution of the script added under it when the specified push button is pressed.
  2. is button () pressed?: The block returns the state of the specified push button. If the button is pressed it returns True or else False.
Note: Make sure you have the latest version of the firmware uploaded to Quarky. You can learn more here: https://ai.thestempedia.com/docs/quarky/quarky-toubleshooting/updating-quarky-firmaware-with-pictoblox/

Example 1: Making Tobi move with Quarky Switches (Stage Mode)

The example demonstrates how to make the sprite movement with Quarky buttons in Stage Mode.

Note: The Stage mode is a mode of working in PictoBlox in which we can interact with Quarky in real-time. If you disconnect the board with Pictoblox, you can no longer interact with the Quarky. In this mode, you can make games and animations by interacting with Quarky or any other prototyping board.

Script:

Output:

Example 2: Torch with Quarky (Upload Mode)

The example demonstrates how to make the lights of Quarky turn ON when the Quarky left switch is pressed in Upload Mode.

Note:  Upload mode is one of the two modes you can write your programs in Pictoblox. This mode allows you to write scripts and upload them to the board so that you can use them even when it is not connected to your computer. For example, you need to upload a script for making moving robots.

Script:

Python Coding

In PictoBlox, you have the following Python function available for the tactile switches:

  1. readpushbutton(button = “L”): The function returns the state of the specified push button. If the button is pressed it returns True or else False.

Example 1: Making Sprite move with Quarky Switches (Stage Mode)

The example demonstrates how to make the sprite movement with Quarky buttons in the stage mode.

Note: The Stage mode is a mode of working in PictoBlox in which we can interact with Quarky in real-time. If you disconnect the board with Pictoblox, you can no longer interact with the Quarky. In this mode, you can make games and animations by interacting with Quarky or any other prototyping board.
sprite = Sprite('Tobi')
quarky = Quarky()

while True:
  if quarky.readpushbutton("L"):
    sprite.move(-10)
  elif quarky.readpushbutton("R"):
    sprite.move(10)

Output:

Example 2: Torch with Quarky (Upload Mode)

The example demonstrates how to make the lights of Quarky turn ON when the Quarky left switch is pressed in Upload Mode.

Note:  Upload mode is one of the two modes you can write your programs in Pictoblox. This mode allows you to write scripts and upload them to the board so that you can use them even when it is not connected to your computer. For example, you need to upload a script for making moving robots.
from quarky import *

quarky.setbrightness(20)
while True:
  if quarky.readpushbutton("L"):
    quarky.drawpattern("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")

  else:
    pass
    quarky.cleardisplay()

Conclusion

In conclusion, Quarky‘s tactile switches can be used to control movement, lights, and more with Pictoblox. The tactile switches can be configured in Quarky Settings and can be used in both Stage Mode and Upload Mode. The blocks and functions are available in Pictoblox make it easy to program the Quarky tactile switches.

Table of Contents