Table of Contents

Function Definition: playtone(note = "C4", duration_factor = 1)

Parameters

NameTypeDescriptionExpected ValuesDefault Value
notestringThe note to be played."C4","D4","E4","F4","G4","A4","B4", "C5","D5","E5","F5","G5","A5","B5", "C6","D6","E6","F6","G6","A6","B6", "C7","D7","E7","F7","G7","A7","B7""C4"
duration_factorintThe factor by which the duration needs to be changed.1, 2, 4, 8, 161

Description

The function plays the tone on the speaker for the specified note and duration. The duration is calculated by the factor.

Actual playtime = 1 / duration factor

Example

The example demonstrates using the Quarky touch display to make a touch piano in the Python Coding Mode.

Code

sprite = Sprite('Tobi')
quarky = Quarky()

while True:
  if quarky.ispadtouched("T1"):
    quarky.drawpattern("bbbjjbjjbjjbbjjbjjjbjjbjjjbjjbjjbbb")
    quarky.playtone("C4", 8)

  if quarky.ispadtouched("T2"):
    quarky.drawpattern("cccjcccjcjjjjcjcjjcccjcjjcjjjcjjccc")
    quarky.playtone("D4", 8)

  if quarky.ispadtouched("T3"):
    quarky.drawpattern("fffjfffjfjjjjfjfjjfffjfjjjjfjfjjfff")
    quarky.playtone("E4", 8)

  if quarky.ispadtouched("T4"):
    quarky.drawpattern("dddjdjdjdjjdjdjdjjdddjdjjjjdjdjjjjd")
    quarky.playtone("F4", 8)

  if quarky.ispadtouched("T5"):
    quarky.drawpattern("gggjgggjgjjgjjjgjjgggjgjjjjgjgjjggg")
    quarky.playtone("G4", 8)

Output

Read More
Learn how to create a dance sequence with Quadruped and Music using PictoBlox in this tutorial.

Introduction

The example demonstrates how to create a dance sequence with Quadruped with Music.

Code for Stage Mode

  1. When Quarky‘s left pushbutton is pressed, it will wait for 1 second and play a sound. 
  2. After that, Quadruped will wave its right hand and move back to the “home position. Then 
  3. Quarky will play different tones and Quadruped will do different actions. 
  4. Finally, Quadruped will move back to the “home position.
sprite = Sprite('Tobi')
quarky = Quarky()
import time

quad=Quadruped(4,1,8,5,3,2,7,6)


quad.home()
while True
	quarky.playsound("QuarkyIntro")
	quad.action("right hand wave",700,2)
	quad.home()
	quarky.playtone("E5",8)
	quad.action("front back",700,3)
	quarky.playtone("C4",8)
	quad.action("bodyshake2",700,3)
	quarky.playtone("D4",8)
	quad.action("bodyshake3",700,3)
	quarky.playtone("E4",8)
	quad.action("bodyshake4",700,3)
	quarky.playtone("C5",8)
	quad.action("updown1",700,3)
	quad.home()

Code for Upload Mode

You can also make the Quadruped dance work independent of PictoBlox using the Upload Mode. For that switch to upload mode. 

Output

Explore: Try to create your dance sequence.
Read More
All articles loaded
No more articles to load