Skip to content

Commit

Permalink
Add method to make cozmo play a series of notes (Closes #6)
Browse files Browse the repository at this point in the history
  • Loading branch information
gbroques committed Mar 24, 2018
1 parent cc10f7c commit f5ffeed
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
7 changes: 2 additions & 5 deletions song_match/song_match.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from cozmo.objects import EvtObjectTapped
from cozmo.objects import LightCube2Id
from cozmo.robot import Robot

from song_match.cube import NoteCube
Expand All @@ -15,7 +14,6 @@ class SongMatch:
def __init__(self):
self._robot = None
self._song = MaryHadALittleLamb()
self._prev_cube = LightCube2Id
Note.init_mixer()

async def play(self, robot: Robot) -> None:
Expand All @@ -34,9 +32,8 @@ async def __setup(self) -> None:

self.__turn_on_cube_lights()

await self._robot.play_note(Note('E4'))
await self._robot.play_note(Note('D4'))
await self._robot.play_note(Note('C4'))
notes = [Note('E4'), Note('D4'), Note('C4')]
await self._robot.play_notes(notes)

async def __tap_handler(self, evt, obj=None, tap_count=None, **kwargs):
cube = evt.obj
Expand Down
5 changes: 5 additions & 0 deletions song_match/song_robot.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from asyncio import sleep
from typing import List

from cozmo.anim import EvtAnimationCompleted
from cozmo.anim import Triggers
Expand All @@ -23,6 +24,10 @@ def __init__(self, robot: Robot, song: Song):
self._animation_complete = True # Keep track of when animation is completed
self._robot.world.add_event_handler(EvtAnimationCompleted, self.__on_animation_completed)

async def play_notes(self, notes: List[Note]) -> None:
for note in notes:
await self.play_note(note)

async def play_note(self, note: Note) -> None:
cube_id = self._song.get_cube_id(note)
note_cube = self.__get_note_cube(cube_id)
Expand Down

0 comments on commit f5ffeed

Please sign in to comment.