"

Chapter 1 – Introduction to Python with Zumis

1.4 – Light, Emotions, and Sounds

This module helps students learn how to program Zumi’s lights, emotions and sounds.

Lights
Zumi has headlights and brake lights that can be programmed using LEDs. Zumi has eight LEDs on the board, but only three on the left side indicate charging state, one on the right side indicates that the Pi started successfully and two on the front are for headlights. The back LEDs are much easier to see; they are the red ones on the back of Zumi. The following functions are available to control Zumi’s LEDs:

* all_lights_on()

  • all_lights_off()
  • headlights_on()
  • headlights_off()
  • brake_lights_on()
  • brake_lights_off()
  • hazard_lights_on()
  • hazard_lights_off()
  • signal_left_on()
  • signal_left_off()
  • signal_right_on()
  • signal_right_off()

To get started with controlling Zumi’s LEDs, import the Zumi and time libraries, and create a new Zumi object.

from zumi.zumi import Zumi
import time

zumi = Zumi()

We can now test the different light configurations that Zumi offers using the code below:

zumi.signal_right_on()
zumi.forward(duration = 3)
zumi.turn_right()
zumi.signal_right_off()
zumi.forward()

 Emotions
Zumi has a personality and can detect human emotions. The Personality library allows you to program Zumi’s personality. To get started, import the Zumi, Screen, and Personality libraries and create new objects for Zumi, Screen, and Personality.

from zumi.zumi import Zumi
from zumi.util.screen import Screen
from zumi.personality import Personality
import time

zumi = Zumi()
screen = Screen()
personality = Personality(zumi, screen)

Here are some of the functions available in the Personality library:

* happy()

  • celebrate()
  • angry()
  • look_around()
  • look_around_open()
  • disoriented_leh()
  • disoriented_right()
  • awake()

To make Zumi perform a personality function, call the function on the Personality object.

personality.happy()

Zumi’s personality can also express emotions through the OLED (organic LED) screen. Zumi has a variety of different “eye” expressions, including:

* close_eyes()

  • sleepy_eyes()
  • sleepy_left()
  • sleepy_right()
  • blink()
  • look_around_open()
  • sleeping()
  • look_around()
  • glimmer()
  • sad()
  • happy()
  • hello()
  • angry()

To display an expression on the screen, call the screen class with the desired function, such as:

screen.sad()

Sounds
Zumi can also play sounds to match her emotions. Sound can be measured in frequency and amplitude. Use play_note() to play various notes. The first parameter is the note you want to play (anywhere from C2 to B6). The second parameter is optional and denotes the amount of time you want the note to play in milliseconds.

from zumi.protocol import Note

zumi.play_note(Note.C4)
zumi.play_note(Note.D4)
zumi.play_note(Note.E4)
zumi.play_note(Note.F4)
zumi.play_note(Note.G4)
zumi.play_note(Note.A4)
zumi.play_note(Note.B4)
zumi.play_note(Note.C5)

 Conclusion
With the Zumi robot, we have learned how to program lights, emotions, and sounds. We can now create our own unique experiences with Zumi.

Demo Video 

Questions