In previous post, I analyzed how to expand the skills of a demo model “Rain or Shine?”. In this post, I would like to analyze another model called “Brain Game”. You could find its step-by-step instruction from LEGO Spike Prime App: Unit Plans -> Life Hacks -> Brain Game.
In the original program, the device will identify the red block and display its index on the light matrix. After upgrading the code, not only those functions, the model could also speak out the color name of those blocks. The final effecct is shown in the below video.
Unlike the “Rain or Shine?” model, this model keeps most of the original program unchanged, and enhances part of the functionality. I will focus on explaining the enhanced program and introducing its mechanical structure. So let’s start!
“when Left button pressed” Code Segment
When left button on the Technic Hub is pressed, this program will start. the motor conntecting to Port C runs anti-clockwise for 2.1 seconds to push the 2*16 plate to the right most position. Here “2.1 seconds” is a result of trial and error. The purpose is to ensure that the plate always starts from an accurate initial position.
After that, the program repeats 5 times to move plate to the left. Please note that “Sensor Port … colour” block returns colour code, which is a number between -1 and 10. For example, 0 represents Black, 3 represents Blue, 4 represents Light Blue, etc. The program records those colour code into a list called Candy1. Since it is not easy to remember what color each number repersents, the program calls “GetColorName” block to convert those color codes into color names. I will introduce this self-defined block “GetColorName” in the following part.
In order to move color blocks (which is buckled onto the 2*16 plate) one by one over the color sensor, the motor runs clockwise 95 degrees in each iteration, so that the next color block could be moved to face color sensor squarely.
Please note that “95 degrees” is also a result of trial and error. The degree is decided by the size of wedge belt wheel and the distance between adjacent color blocks.
This self-designed block is used to convert color code into color name. It stores the converted color code in a variable “color_name”. This variable will be passed as input parameter of “play sound … until done” block to play the corresponding sound file.
“when I receive Check” Code Segment
This code segment keeps the same as that of the original program. It uses “item # 9 in Candy1” to find out the index of an item whose value is 9 (representing Red color), and then light up the whole row in the light matrix, as shown in the below image.
This model structure is fun because it is like an automatic mechanism to move out blocks one by one, which reminds me some models used in WRO competition. For example, WRO 2017 elementary group, which I introduced in another post, requires to design a device being able to pick up and push out blocks. The mechaical structure of this project could be referred to when we design some competition models.
Looking at the photo below, you could notice that the upper panel is a bit tilted, so the weight of the panel, Technic Hub and medium motor will press against the 2*16 plate, increasing the friction between it and wedge belt wheel to avoid slipping.
The 2*16 plate is set up on two shelves. It could only move back and forth in one dimension. Color blocks attached on the plate face toward the colour sensor (installed on the base panel) so that the colour could be identified.
The above two points are the key of the design. Actually, using beam to fix the left openning side, the structure could even stand up to move the plate out in vertical direction.
That is all for the analysis of the LEGO Spike model. Is it easy to get started? Start to build your own model and expand its skills. Enjoy it!
Note: All the analysis articles are copyright products of http://www.thecodingfun.com. Anyone re-posting them should credit author and original source. Anyone using them for commercial purposes or translating them into other languages should notify TheCodingFun and get confirmation first. All Rights Reserved.