Examples

Codey Rocky Projects

1. Change Codey's Emotions with Buttons

1) Drag a when button () is pressed block from the Events category to the Scripts area.

2) Drag a play sound () block from the Speaker category.

3) Drag a show image () block from the Looks category.

4) Click "Upload" to upload the program to Codey.

5) Press Button A to see how Codey looks!

2. Use Codey to Create LED Animations

1) Drag a when Codey is shaking block from the Events category to the Scripts area.

2) Drag a show image () for () secs block from the Looks category, and draw the following image. Reset the time to 0.3.

3) Add a show image () for () secs block from the Looks category, and draw the following image. Reset the time to 0.3.

4) Add another show image () for () secs block from the Looks category, and draw the following image. Reset the time to 0.3.

5) Add a Control block repeat () to wrap up the three show image () for () secs blocks. Reset the number to 6.

6) Drag a play sound () block from the Speaker category to add some sound effects. Set the sound as "jump".

7) Click "Upload" to upload the program to Codey.

8) Try shaking Codey to see the rabbit jumping!

3. Turn Codey into a Musician

1) Drag an Event block when button () is pressed to the Scripts area.

2) Add four play note () for () beats blocks from the Speaker category. Set the corresponding note as C4, E4, F4, and A5.

Volume Control Script

3) Drag a when Codey starts up block from the Events category.

4) Add a Speaker block set volume to ()% and a Sensing block gear potentiometer value, so that we can adjust the gear to change volume.

5) Add a Control block forever, so we are able to adjust the sound volume all the time.

6) Click "Upload" to upload the program to Codey.

7) Press Button A to see how Codey plays music!

1) Drag an Event block when Codey starts up to the Scripts area.

2) Add a Looks block show image () for () secs. Add an Operators block pick random () to () to make Codey blink eyes randomly. Set the number as 2 and 5.

3) Add another Looks block show image () for () secs. Draw the following image, and set the time as 0.2.

4) Drag a Control block forever to wrap up the two show image () for () secs blocks, so Codey will keep blinking eyes.

5) Click "Upload" to upload the program to Codey.

6) Check Codey to see it blink eyes!

5. Make Codey Rocky Identify Colors

1) Drag an Event block when Codey starts up to the Scripts area.

2) Add a Control block if () then (), and a Sensing block the color detected is ()?.

3) Add a Lighting block RGB LED lights up () to make the LED lights up red when the color detected is red. Drag a play sound () block and change the sound to "score" to add some sound effects.

4) We want Codey Rocky to detect color blue. Right click to duplicate the blocks. Change the color to blue.

5) Add a Control block forever to create a loop.

6) Click "Upload" to upload the program to Codey.

7) Have a try!

Note: keep the IR sensor face-down.

6. Make Codey Rocky Avoid Obstacles

1) Drag an Event block when Codey starts up to the Scripts area.

2) Add a Looks block show image ().

3) Drag an Action block () at power ()%, a Control block wait until (), and a Sensing block obstacles ahead?. Keep all default values.

4) When Codey Rocky detects obstacles ahead, we want it to avoid them by moving backward and turning right, so we need to add three Action blocks: stop moving, move backward at power ()% for () secs, and turn right at power ()% for () secs.

5) Add a Control block forever to make Codey Rocky keep avoiding obstacles.

6) Click "Upload" to upload the program to Codey.

7) Check how Codey Rocky manages to stay away from obstacles.

Note: adjust the IR sensor to face-forward.

7. Use Codey to Make Sprites Play Instruments

This project combines stage programming with Codey.

Before we start, please toggle to disable Upload Mode.

1) Drag an Events block when button () is pressed.

2) When Button A is pressed, we want the sprite to receive the message. We need to add an Events block broadcast (). Click to create a new message "A".

3) Add a new sprite. Under "Sprites", click "+". From the pop-up Sprite Library window, choose "Drum" and click "OK".

4) Make sure "Drum" is selected. Drag an Event block when I receive (). Add a Sound block start sound () and keep the default "high tom".

5) Apply some animation effect to "Drum". Add a Looks block switch costume to (), and set the costume as "drum-b". Add a Control block wait () seconds, and change the value to 0.2. Add another Looks block switch costume to (), and set the costume as "drum-a".

6) Save your project. Press Button A to see what happens!

8. Design a Controller for Codey Rocky

This project combines stage programming with Codey.

Before we start, please toggle to disable Upload Mode.

Program Sprites

1) Under "Sprites", click "×" to delete the default sprite "Panda", and click "+" to add a new sprite. From the pop-up Sprites Library, choose "Arrow1" and click "OK".

2) Select "Arrow1". From the Events category, drag a when this sprite clicked block and a broadcast () block. Create a new message "Right".

3) Right click "Arrow1" to duplicate. The new sprite will automatically be named "Arrow2". Click "Costumes" to change the costume. Select costume 2. When done, click "×" finish costume setting. In the Scripts area, click to create a new message "Left".

4) Repeat step 3 to add another sprite "Arrow3" to broadcast message "Down".

5) Repeat step 3 to add another sprite "Arrow4" to broadcast message "Up".

6) Click to reposition the four arrows as the following image.

Program Codey

7) Choose "Codey" under "Devices". Drag an Events block when I receive () and set the message as "Left". Add an Action block turn left at power ()% for () secs, and keep the default value.

8) Drag an Events block when I receive () and set the message to "Right". Add an Action block turn right at power ()% for () secs, and keep the default value.

9) Drag an Events block when I receive () and set the message to "Up". Add an Action block move forward at power ()% for () secs, and keep the default value.

10) Drag an Events block when I receive () and set the message to "Down". Add an Action block move backward at power ()% for () secs, and keep the default value.

11) Save your project. Click the arrows on the stage and see how Codey Rocky moves!

9. Make a Number Bomb Game

1) Drag an Event block when Codey starts up to the Scripts area.

2) Choose Variables category and click "Make a Variable". Name the variable "Number" and click "OK".

3) Add a Variables block set Number to (), and keep default value.

4) Add a Looks block show () until scroll done and a Variables block Number.

5) Add an Events block when button () is pressed, and keep the default value. Add a Variables block change Number by () and also keep the default value.

6) Add a Speaker block play sound () to apply some sound effects to the game.

7) Click the following two blocks to duplicate and add them to the play sound () block.

8) Add a Control block if () then () to set how the game ends.

9) From the Operators category, drag a () > () block and a pick random () to () block. Set the number to 10 and 20. Then add a Variables block Number.

10) Add a Looks block show image () and draw the following image. Add a Speaker block play sound (), and set the sound to "explosion".

11) Click "Upload" to upload the program to Codey.

12) Have a try!

More Resources

Example Programs

You can find a variety of built-in example programs in mBlock 5. Go to the Project Management page to access those programs.

Last updated