USING FUNCTIONS

  1. Learning Objectives Understand how to group a set of moves into one “function.” Practice reusing that function to simplify the program.

  2. Materials Cubetto robot and control board Function block (often blue or white, depending on the set) The same turn and forward blocks from Lesson 1 A simple map or grid

  3. Activity Steps Review (3 minutes)

Recap how Cubetto moves with single blocks (Lesson 1). Show children the “function block” slot on the board. Create a Function (5 minutes)

Example: Let’s define a “square dance” function—two forward moves and a turn left. Put forward, forward, turn left in the function section. Call the Function (5 minutes)

In the main sequence, place the “function call” block (the block that tells Cubetto “use that mini-program”). Press “Go.” Cubetto executes the entire mini-program. Demonstrate using the function multiple times: if you call the function twice, Cubetto will do the same sub-sequence again. Practice & Challenges (5 minutes)

flowchart TB
    A((Start)) --> B[Define Function: "StepLeftDoubleFwd"]
    B --> C[Inside Function: <br/>• Forward Block <br/>• Forward Block <br/>• Turn Left Block]
    C --> D[End Function Definition]
    D --> E[Main Program: Place Function Call (StepLeftDoubleFwd)]
    E --> F[Place Function Call (StepLeftDoubleFwd)]
    F --> G[Place Function Call (StepLeftDoubleFwd)]
    G --> H[Place Function Call (StepLeftDoubleFwd)]
    H --> I[Press GO]
    I --> J((Cubetto Executes: Forward, Forward, Left) x4))

Have children incorporate the function call into bigger sequences. For instance, “function call, turn right, function call.”

  1. Reflection Ask them how using a function can make coding “easier” and “shorter.” Emphasize how we can reuse the same moves without placing each block every time.