Skip to content

Cozmo's rainbow cube #229

@Readyornot69

Description

@Readyornot69

import cozmo
from cozmo.util import degrees
import time

Rainbow colors (Red, Orange, Yellow, Green, Blue, Indigo, Violet)

rainbow_colors = [
cozmo.lights.Color(red=255, green=0, blue=0), # Red
cozmo.lights.Color(red=255, green=165, blue=0), # Orange
cozmo.lights.Color(red=255, green=255, blue=0), # Yellow
cozmo.lights.Color(red=0, green=255, blue=0), # Green
cozmo.lights.Color(red=0, green=0, blue=255), # Blue
cozmo.lights.Color(red=75, green=0, blue=130), # Indigo
cozmo.lights.Color(red=238, green=130, blue=238) # Violet
]

def cozmo_program(robot: cozmo.robot.Robot):
# Find the first available cube
cube = robot.world.wait_for_observed_light_cube(timeout=30)

# If no cube is found, exit
if not cube:
    robot.say_text("No cube found").wait_for_completed()
    return

# Cycle through the rainbow colors for the cube's lights
for color in rainbow_colors:
    # Set the cube light color
    cube.set_light(color)
    time.sleep(1)  # Wait for 1 second before changing the color

# After cycling through, turn the lights off
cube.set_light(cozmo.lights.off)
robot.say_text("Rainbow pattern completed!").wait_for_completed()

cozmo.run_program(cozmo_program)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions