Table of Contents

Robot Pet – Python

Example Description
The example demonstrates how to make a vertical robot pet that senses the hand on the IR sensor and acts accordingly in the Python Coding Environment.

Code

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

quarky.setorientation(2)
quarky.setirthreshold("IRL", 3000)
quarky.setirthreshold("IRR", 3000)

while True:
  if quarky.getirstate("IRL"):
    if quarky.getirstate("IRR"):
      quarky.cleardisplay()

    else:
      pass
      quarky.runrobot("LEFT", 100)
      time.sleep(0.3)
      quarky.stoprobot()

  else:
    pass
    if quarky.getirstate("IRR"):
      quarky.runrobot("RIGHT", 100)
      time.sleep(0.3)
      quarky.stoprobot()

    else:
      pass
      quarky.showemotion("happy")
      quarky.playsounduntildone("QuarkyIntro")

Output