[No.18] Punch the Bear for a KO! A Get-Moving Machine

Fall is a great season for eating, reading and sports... but lots of people enjoy eating and reading and keep putting off exercise, right? Let's build "Punch the Bear for a KO!", a machine that keeps you motivated so you can stick with a little exercise every day instead of giving up after three days!!

What You Need & Getting Ready
- SPACEBLOCK Standard Package [SPACEBLOCK board, USB cable, battery box]
- Infrared obstacle avoidance sensor module (obstacle avoidance sensor)
- 180° micro servo motor (servo motor)
- 8×8 RGB LED matrix panel (LED panel)
- Jumper wires [3 pin header–pin socket wires × the number of wires you want to extend]
- A computer for programming

Connect the Expansion Parts to SPACEBLOCK

Check the details of the connections in the next picture.

Make the Bear and Other Craft Parts



Stick the bear on the long stick and the grass on the front of the case, and it really starts to look the part!

At this point, it's easier if you make the program and fine-tune things before moving on, but here we'll keep going and finish the whole machine.
Take the grass decoration off for a moment, and put the SPACEBLOCK and everything else inside the case. Use the photo as a guide to fix the obstacle avoidance sensor and the LED panel on the inside, and pass the servo motor's jumper wires through the hole to the inside.



How to Use the Obstacle Avoidance Sensor and Read Its Values
The program uses the obstacle avoidance sensor value. How to use the obstacle avoidance sensor is explained in detail in "[No.10] Invent a Trash Can That Opens by Itself!", but this time we use a different block, so let's do a quick review.
The obstacle avoidance sensor can use infrared light to detect whether there's an obstacle within a certain distance. It only sends two kinds of information, whether there "is" or "isn't" an obstacle, so it's a digital input.
When there's no obstacle, the obstacle avoidance sensor raises the voltage on the pin it's plugged into and sends the value true to the program. When there's an obstacle, it lowers the voltage and sends the value false.True and false are called Boolean values, and they're used in conditions. In the program, use the [Read digital voltage of (A0)] block to get the value.

To set the detection distance, turn the potentiometer on the obstacle avoidance sensor with a screwdriver. We want it to react to a punch, so if the distance is too short, you might end up punching the machine itself by accident. Set it to react from a bit of a distance.

A Program That Knocks the Bear Down When a Punch Comes

[if ( ) then … else …] The condition of this block is set to the obstacle avoidance sensor value. The obstacle avoidance sensor value is a Boolean value, true or false. If a Boolean value is true, the condition is met. If it's false, the condition is not met.
Now we have a bear that falls down when you punch it. To get you even more motivated to exercise, let's add a way to count your punches.
Count Your Punches


If you take the current value out of a variable, add 1, and put it back into the variable, the variable goes up by 1 every time it repeats. This is handy when you program things like counting or keeping score, so remember it!
Now we can count, but showing the count in the console means you can't see it when you're using the "Punch the Bear for a KO!" machine. Let's add one more idea.
A Colorful Break Every 10 Punches

That finishes "Punch the Bear for a KO!"
Once you've written the program to SPACEBLOCK, start punching! You can enjoy endless exercise with a break every 10 punches. Anything coming close to the sensor works, so it's OK to use high kicks instead of punches. If you put it lower, you can use it for high-knee exercises too!

When you reach 10, take a short rest during the LED show. The count resets to 0, so keep going with the next 10!
