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)

Writing the code

The code for the mechanical bird will use the ultrasonic sensor as both the eyes and to trigger movement. The goal is to mimic a bird in flight looking for prey, so we will work to ensure the legs move with the head gesture as well as the wing mechanics.

The ports

You will connect the ultrasonic sensor into port B. You will plug the large motor into port F. You will plug the two medium motors into ports C and D.

Figure 4.35 – Port view in the software

Calibrating the motors

This first code stack will make sure that the head and wing motors are all set to position 0 before being activated to ensure everything works smoothly and properly:

  1. Under the when program starts block, insert a purple light up block that activates the lights on ultrasonic sensor B lighting up to 0 0.
  2. Add a pink movement block named set movement speed to and make it 15%.
  3. Add a blue set speed to motor block, set it to 10%, and change it to...