how to make a magic 8 ball on micro bit

Micro Bit Magic 8 Ball: How to Create One

By Michael Thompson
AD

The Micro:bit is a fantastic tool for teaching kids about coding and electronics, and it's also great for sparking creativity. One fun project you can make with a Micro:bit is a replica of the classic Magic 8 Ball. This Seymour Papert-inspired toy combines learning and play, making it an engaging STEM activity.

Making a Magic 8 Ball on a Micro:bit involves a bit of coding and creativity. You'll use the device's features, like its LEDs and accelerometer, to create an interactive game. So, let's dive in and start creating our own magical fortune-telling device!

The Basics: Setting Up Your Micro:bit

Before you start programming, ensure your Micro:bit is set up correctly. You'll need to connect it to your computer and install the Micro:bit firmware if you haven't already. Once connected, you'll see the five-by-five LED grid lighting up.

AD
Magic 8 Ball, Open Source, Customizable, Fun and Easy to Build
Magic 8 Ball, Open Source, Customizable, Fun and Easy to Build
DIY Hacks & How To's: Digital Magic 8 Ball
DIY Hacks & How To's: Digital Magic 8 Ball
Microbit Coding Activity – Magic 8 Ball Game Programming Task 6th-11th Grade
Microbit Coding Activity – Magic 8 Ball Game Programming Task 6th-11th Grade

The Micro:bit uses a version of the BBC BASIC language. But don't worry if you're new to programming; the learning curve is gentle, and you'll pick it up quickly. You can use various tools to program your Micro:bit, such as Microsoft MakeCode or the BBC BASIC interpreter.

Understanding the Magic 8 Ball Layout

The Magic 8 Ball typically has 20 answers, divided into five categories: five favorable, five uncertain, and five unfavorable. To represent this on the Micro:bit, you'll use the LED display and the device's buttons. You'll 'shake' the Micro:bit to get an answer, using the built-in accelerometer to detect the motion.

How to make an emoji magic 8-ball - Today's Parent
How to make an emoji magic 8-ball - Today's Parent
(Super Quick) Magic 8 Ball Costume!
(Super Quick) Magic 8 Ball Costume!
MicroBit Magic 8 Ball with MicroPython
MicroBit Magic 8 Ball with MicroPython

For the display, you can show the answer using the LED grid or a short text message on the Micro:bit's display (if you're using the MakeCode platform). For button interaction, you can use the A and B buttons to select Yes/No or ask a new question.

Creating the Magic 8 Ball Answers Pool

You'll need to create an array of strings containing all 20 answers. Here's an example in MakeCode using JavaScript blocks:

AD

```javascript let answers = [ "It is certain", "It is decidedly so", "Without a doubt", "Yes, definitely", "You may rely on it", "Ask again later", "Better not tell you now", "Cannot predict now", "Concentrate and ask again", "Reply hazy, try again", "Outlook not so good", "My reply is no", "My sources say no", "Very doubtful", "You decide", "Friendship. True until the end." ]; ```

Digital Magic 8 Ball
Digital Magic 8 Ball
magic 8 ball !!
magic 8 ball !!
Magic 8 ball – Microbit #3DThursday #3DPrinting
Magic 8 ball – Microbit #3DThursday #3DPrinting
How to Make a Custom Magic 8 Ball | Find a Gift For
How to Make a Custom Magic 8 Ball | Find a Gift For
How To: Hack a Magic 8-Ball - Make:
How To: Hack a Magic 8-Ball - Make:
An electronic magic 8 ball #Arduino
An electronic magic 8 ball #Arduino

Programming the Magic 8 Ball

Now that you have your answers set up, let's write the code to bring your Magic 8 Ball to life. Here's a basic outline of what your program should do:

1. Initialize a random number generator. 2. Display a welcome message on the LED grid or the display. 3. Detect a shake event using the accelerometer to trigger an answer. 4. Display a random answer from the answers array. 5. Allow the user to select Yes/No using the A/B buttons to ask a new question.

AD

Implementation with MicroPython

If you're using MicroPython, here's a simple implementation of the Magic 8 Ball logic:

Electronic Magic 8 Ball and Eyeball
Electronic Magic 8 Ball and Eyeball
Magic 8-Ball Gets A Modern Makeover
Magic 8-Ball Gets A Modern Makeover
How to make an emoji magic 8-ball - Today's Parent
How to make an emoji magic 8-ball - Today's Parent

```python import random import microbit answers = [ "It is certain", "It is decidedly so", "Without a doubt", "Yes, definitely", "You may rely on it", # ... rest of the answers ] def shake detects(): # Your shake detection code here pass while True: if shake detects(): display(random.choice(answers)) if microbit.button_a.was_pressed(): # Ask a new question if microbit.button_b.was_pressed(): # Select Yes/No ```

Implementation with MakeCode

In MakeCode, you can use the following JavaScript blocks to create your Magic 8 Ball:

AD

```javascript let shake = 0; let answers = [ "It is certain", "It is decidedly so", "Without a doubt", // ... rest of the answers ]; basic.forever(() => { shake = input.acceleration(Dimension.X) > 700; if (shake && shake < 1) { basic.showString(randomString(answers)); } if (input.buttonIsPressed(Button.A)) { // Ask a new question } if (input.buttonIsPressed(Button.B)) { // Select Yes/No } }); ```

You can customize the shake detection threshold in the first line of the while loop or the forever block, depending on whether you're using MicroPython or MakeCode.

Customizing Your Magic 8 Ball

Once you've got the basics working, you can start customizing your Magic 8 Ball. Here are some ideas:

Adding Visual Effects

You can animate the LED grid to create visual effects when asking or selecting an answer. For example, you can make the whole LED screen flash white or display a 'thinking' spinner.

Increasing the Answer Pool

You can add more answers to the answers array to expand your Magic 8 Ball's knowledge. You can also categorize the answers and select them randomly based on categories for more versatility.

Remember, the Micro:bit's built-in displays and buttons allow for numerous creative possibilities. Don't be afraid to experiment and make the Magic 8 Ball your own!

Creating a Magic 8 Ball on a Micro:bit is an engaging and educational project that combines coding, electronics, and fun. Not only will you learn how to use the Micro:bit's features, but you'll also gain a deeper understanding of programming concepts. So, go ahead, roll that virtual ball, and let the magic begin!

AD