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 the dragster

The code for this project is designed to achieve the following objectives:

  • The dragster needs to count down 3-2-1 to make sure people have time to move out of the way.
  • The dragster needs to stop when it sees the red (or the color of choice) finish line.
  • The dragster needs to display the time to avoid human error when using a stopwatch.

Connecting to the proper ports

Before we begin to code, you need to make sure you have all the parts properly connected to the Intelligent Hub. Start with the motors. The motors should be plugged into ports A and E. It does not matter which motor goes into which port if they are A and E, since the dragster will only move forward and backward.

Your color sensor will go into port C. This sensor will help your dragster identify and stop at the finish line:

Figure 6.47 – The port view in the software

For this program, you will have two code stacks. Additionally, you will be...