Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Design Innovative Robots with LEGO SPIKE Prime

You're reading from  Design Innovative Robots with LEGO SPIKE Prime

Product type Book
Published in Jan 2022
Publisher Packt
ISBN-13 9781801811576
Pages 264 pages
Edition 1st Edition
Languages
Concepts
Author (1):
Aaron Maurer Aaron Maurer
Profile icon Aaron Maurer

Table of Contents (9) Chapters

Preface Chapter 1: Getting Started with SPIKE Prime Chapter 2: Building an Industrial Robot Claw Chapter 3: Building a LEGO Guitar Chapter 4: Building a Mechanical Bird Chapter 5: Building a Sumobot Chapter 6: Building a Dragster Chapter 7: Building a Simon Says Game Other Books You May Enjoy

Chapter 7: Building a Simon Says Game

Handheld games have long been a pastime favorite. Whether you grew up with basic analog games or started with the glory of digital gaming to the now ever-so-powerful phone apps, you cannot argue how fun games are to the human mind.

In this chapter, you will be building and coding a classic handheld game of Simon Says. This chapter is different from the previous chapters as the focus is less on the actual build and more space is given to the code. The goal of this chapter is to increase your coding skills so that you can go and create a favorite game of your own.

Here is a diagram of what your Simon Says game will look like by the end of this chapter:

Figure 7.1 – Simon Says handheld game

In this chapter, you will build and program in the following sections:

  • Building the handheld game
  • Coding Simon Says

Technical requirements

For the building of Simon Says, all you will need is the SPIKE Prime Kit. For programming, you will need the LEGO SPIKE application/software.

Access to the code can be found here: https://github.com/PacktPublishing/Design-Innovative-Robots-with-LEGO-SPIKE-Prime/blob/main/Ch.%207%20SIMON%20SAYS%20.llsp.

You can find the code in action video for this chapter here: https://bit.ly/2ZhBcw3

Building the handheld game

This is a very simple build. Please keep in mind that with a game such as Simon Says, there are countless ways to build the device. The build is kept simple so that you can modify it to your own liking:

  1. Begin the build by starting with the Intelligent Hub.

    Figure 7.2 – Beginning with the Intelligent Hub

  2. On the bottom row of pin holes on the sides of the Intelligent Hub, add two gray H perpendicular connector pins to each side.

    Figure 7.3 – Attaching gray perpendicular connector pins

  3. Attach a purple 11L beam to both sides across the two gray H perpendicular connector pins.

    Figure 7.4 – Attaching purple 11L beams

  4. Next, add four black connector pins to the top-corner pin holes of the Intelligent Hub.

    Figure 7.5 – Inserting four black connector pins

  5. On either side of the Intelligent Hub, attach an azure curved panel to the black connector pins. On the ends of these azure curved panels, insert black connector pins...

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...

Making it your own

Here is the best part of every chapter and build. What will you do to remix the build and the code to make it unique to your own creative power? While Simon Says is a standard game, there are a lot of ways to enhance your build.

Here are a couple of ideas to consider applying to this game:

  • What new graphics could you display besides the solid bars? Arrows? Images?
  • What new sound effects could you add? What are your favorite jingles from movies, cartoons, or video games that you could add?
  • Could you change this from a Simon Says game to a Bop It game? Instead of tilting the Intelligent Hub, could you have the player activate one of the gesture controls such as shaken, tapped, or falling?
  • What if you used a touch sensor or even rotated a motor to add new levels of difficulty to the game?

Summary

This chapter spent a great deal of time on coding using broadcast blocks, variables, lists, and music. The goal was to open your eyes to some new ways to think about robots and coding. As you continue to play Simon Says, what will you do next? How can you combine all the learning from this chapter as well as the previous chapters to create something engaging, fun, and so awesome that everyone will want to learn from you?

Remember, all of these builds in the book are designed to inspire you. Take what you have learned and make something even better and more unique. When you design one of these builds, or remix it to your own liking, please share it with the hashtag #legospikecreations. The world can't wait to see your genius!

Why subscribe?

  • Spend less time learning and more time coding with practical eBooks and Videos from over 4,000 industry professionals
  • Improve your learning with Skill Plans built especially for you
  • Get a free eBook or video every month
  • Fully searchable for easy access to vital information
  • Copy and paste, print, and bookmark content

Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at packt.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at customercare@packtpub.com for more details.

At www.packt.com, you can also read a collection of free technical articles, sign up for a range of free newsletters, and receive exclusive discounts and offers on Packt books and eBooks.

lock icon The rest of the chapter is locked
You have been reading a chapter from
Design Innovative Robots with LEGO SPIKE Prime
Published in: Jan 2022 Publisher: Packt ISBN-13: 9781801811576
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}