Table of Contents

Function Definition: playsound(audio = "QuarkyIntro")

Parameters

NameTypeDescriptionExpected ValuesDefault Value
audiostringThe name of the audio file need to be played."QuarkyIntro", "turningLeft", "turningRight", "goStraight", "UTurnDetected", "oneDetected", "twoDetected", "threeDetected", "fourDetected", "fiveDetected", or "QuarkyBootUp""QuarkyIntro"

Description

The function plays the specified audio on the Quarky speaker. The function does not have any callbacks, so other functions can be executed while this function is running.

Example

The example demonstrates how to run different actions with the Quarky touch sensor to make a disco party in Python Coding Environment.

Code

sprite = Sprite('Cassy Dance')
quarky = Quarky()

import time

sprite.switchcostume('cassy-a')
sprite.gotoxy(0, 0)

while True:
  if quarky.ispadtouched("T1"):
    quarky.playsound("QuarkyIntro")

  if quarky.ispadtouched("T2"):
    quarky.showpattern("party colors")

  if quarky.ispadtouched("T3"):
    time.sleep(0.2)
    sprite.nextcostume()

  if quarky.ispadtouched("T4"):
    quarky.stopaudio()

Output

Read More
This code example shows how to program a humanoid robot to perform a dance routine. Learn how to use the Humanoid object with specific pins to control robot movement.

Introduction

Humanoid is a class in a programming code that is used to control the movements of a humanoid robot. The code provides specific pins to control the robot’s movement, and it allows the robot to perform a series of actions such as dancing, flapping, moving forward, and other actions. We can learn how to program a humanoid robot to dance.

Code

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

humanoid = Humanoid(7,2,6,3,8,1)

quarky.showemotion("surprise")
humanoid.home()
humanoid.move("forward",1000,1)
quarky.playsound("QuarkyIntro")
humanoid.action("flapping",1000,1)
time.sleep(1)
humanoid.action("dance2",1000,1)
time.sleep(1)
humanoid.action("moonwalker",1000,1)
time.sleep(1)
humanoid.action("dance1",1000,1)
time.sleep(1)
humanoid.action("forward",1000,1)
time.sleep(1)
Humanoid.action("tiptoeswing",1000,1)
time.sleep(1)
Humanoid.action("swing",1000,1)
time.sleep(1)
Humanoid.action("flapping",1000,1)
time.sleep(1)
Humanoid.action("updown",1000,1)
Humanoid.home()

Logic

  1. This code is an example of how to program a humanoid robot to perform a dance routine.
  2. The first line code imports the time module for later use.
  3. Then we initialize the Humanoid object with specific pins to control the movement of the robot. The pins are passed as arguments to the Humanoid function.
  4. Furthermore, we involve the Quarky object showing emotion, the humanoid robot moving to its home position, and then moving forward for a specified duration and speed.
  5. Then, Quarky plays a sound, and the humanoid performs a series of different actions, each with specific duration and speed, including flapping, dancing, moving forward, and other actions.
  6. The time. sleep(1) functions are used to pause the program for one second between each action.
  7. Finally, the humanoid returns to its home position at the end of the program.

Output

Read More
All articles loaded
No more articles to load