Skip to content

Sounds and Lights

Mr. James edited this page Sep 27, 2020 · 11 revisions

Sounds

Speaker

image of speaker's location

playTone(tone, duration) ---------------------------

Plays a tone for a set duration from Cutebot's piezo speaker.

Parameters:

  • tone (int) - the frequency of the tones/music notes you want to play
  • duration (float) - the number of seconds you want to play the tone

You can play around with different tones. Below are some commonly used tones.

tone note
262 C4
294 D4
330 E4
349 F4
392 G4
440 A4
494 B4

Examples:

cutebot.playTone(294, 0.5)     # plays a C4 music note for half a second
cutebot.playTone(349, 1.0)     # plays a F4 music note for one second
cutebot.playTone(440, 2.2)     # plays a A4 music note for 2.2 seconds

Lights

Headlights

image of speaker's location

headlights(whichLight, colors) ---------------------------

Controls the two headlights.

Parameters:

  • whichLight (integer): there are four states to choose from
    • 0 = Sets both lights to off
    • 1 = Sets left light only
    • 2 = Sets right light only
    • 3 = Sets both lights
  • colors (array of three integers): RGB color that will be displayed
    • colors[0] = red
    • colors[1] = green
    • colors[2] = blue

Examples:

black = [0, 0, 0]
white = [255, 255, 255]
pink = [255, 192, 203]
red = [255, 0, 0]

cutebot.headlights(0, black)          # turns off the headlights
cutebot.headlights(1, pink)           # sets the left headlight to pink
cutebot.headlights(2, red)            # sets the right headlight to red
cutebot.headlights(3, [80, 255, 80])  # sets both headlights to a light green color

Neopixels

image of speaker's location

pixels(whichLight, colors) ---------------------------

Controls the two neopixels.

Parameters:

  • whichLight (integer): there are four states to choose from
    • 0 = Sets both lights to off
    • 1 = Sets left light only
    • 2 = Sets right light only
    • 3 = Sets both lights
  • colors (array of three integers): RGB color that will be displayed
    • colors[0] = red
    • colors[1] = green
    • colors[2] = blue

Examples:

black = [0, 0, 0]
white = [255, 255, 255]
pink = [255, 192, 203]
red = [255, 0, 0]

cutebot.headlights(0, black)           # turns off the headlights
cutebot.headlights(1, pink)            # sets the left neopixel to pink
cutebot.headlights(2, red)             # sets the right neopixel to red
cutebot.headlights(3, [80, 255, 80])   # sets both neopixels to a light green color

lightsOff() ---------------------------

Turns off all headlights and neopixels.

Parameters:

None

Examples:

cutebot.lightsOff()      # Turns off all LEDs.