Book Image

Design Innovative Robots with LEGO SPIKE Prime

By : Aaron Maurer
5 (1)
Book Image

Design Innovative Robots with LEGO SPIKE Prime

5 (1)
By: Aaron Maurer

Overview of this book

The new LEGO SPIKE Prime is one of the latest additions to the LEGO robotics line of products. This book will help you to enjoy building robots and understand how exciting robotics can be in terms of design, coding, and the expression of ideas. The book begins by taking you through a new realm of playful learning experiences designed for inventors and creators of any age. In each chapter, you'll find out how to build a creative robot, learn to bring the robot to life through code, and finally work with exercises to test what you've learned and remix the robot to suit your own unique style. Throughout the chapters, you'll build exciting new smart robots such as a handheld game, a robotic arm with a joystick, a guitar, a flying bird, a sumobot, a dragster, and a Simon Says game. By the end of this LEGO book, you'll have gained the knowledge and skills you need to build any robot that you can imagine.
Table of Contents (9 chapters)

Coding Simon Says

You are going to code a game of Simon Says. The code will be broken down into six parts, as mentioned here:

  • Code stack 1 – main code
  • Code stack 2 – displaying images for player direction
  • Code stack 3 – displaying images and sound for game sequence
  • Code stack 4 – player input of answers
  • Code stack 5 – game over sequence
  • Code stack 6 – correct choice music sequence

All of the code is dependent on the gyro sensor built within the Intelligent Hub. Instead of using colors and external sensors, everything has been designed to use just the Intelligent Hub.

Let's begin!

Code stack 1 – main code

Please keep in mind that while you put this code stack together, some blocks may not work or make sense until you code out the rest of the code stacks. To ease the flow for you, I have decided to code by stacks.

The first part of this stack will clear and reset all the variables to...