Magic 8 Ball Game
Table of Contents
Are you an indecisive person, or do you want answers to a question that keeps you up all night? Here’s a fun solution: the digital recreation of the “Magic 8 Ball game” using PicoBricks’ 0.96-inch 128×64 pixel I2C OLED display! The original Magic 8 Ball is a playful toy that provides answers, often in the form of “yes” or “no,” to various questions. This time, the Magic 8 Ball game is closer to you than ever before, thanks to OLED displays that bring this mysterious world to life.
OLED display offers the capability to be used as an artificial light source, allowing you to magnify the characters on the screen and reflect them onto any desired plane. This enhances the Magic 8 Ball experience, providing instant answers to your questions or adding to the excitement of your curiosity.
If you’re a gaming enthusiast, OLED technology is perfect for you. OLED-equipped monitors allow you to see every detail in your game, even in dark scenes. With this technology, you can truly immerse yourself in your gaming experience and gain an edge over your competitors. Furthermore, OLED displays have a significant impact on everyday life. They can project road and traffic information onto smart glasses and car windshields, enhancing safety and convenience. Easy access to information and clear visuals makes OLED technology an essential part of modern life. PicoBricks’ 0.96-inch OLED display is designed to bring you a magical experience. Whether you’re making decisions or diving into the world of entertainment, let the OLED display make your moments brighter.
Ask The Magic 8 Ball!
Details and Algorithm
This Python code brings the classic “Magic 8 Ball” toy into the digital realm using a PicoBricks device and a 0.96-inch OLED display. It continuously displays “Magic8PicoBricks” on the OLED display and awaits a button press. When the button is pressed, it randomly selects a response from a predefined list and displays a countdown with LED activation. The chosen response is then displayed for 3 seconds before clearing the screen for the next question. This code recreates the whimsical fun of the Magic 8 Ball in a digital format, offering quick and nostalgic answers to user queries.
Components
1xPicoBricks
Wiring Diagram
MicroBlocks Codes of PicoBricks
PicoBricks IDE Codes of PicoBricks
MicroPython Codes of PicoBricks
<pre><code class="python">
from time import sleep
from machine import Pin
from machine import I2C
from picobricks import SSD1306_I2C
import machine
import time
i2c = I2C(0, scl=Pin(5), sda=Pin(4), freq=200000)
oled = SSD1306_I2C(128, 64, i2c, addr=0x3c)
pin_button = machine.Pin(10, machine.Pin.IN)
import random
pin_led = machine.Pin(7, machine.Pin.OUT)
oled.fill(0)
blank = " "
situation = "It is certain. It is decidedly so. Without a doubt. Yes definitely. You may rely on it. As I see it, yes. Most likely. Outlook good. Yes. Signs point to yes. Reply hazy, try again. Ask again later. Better not tell you now. Cannot predict now. Concentrate and ask again. Don't count on it. My reply is no. My sources say no. Outlook not so good. Very doubtful.".split(".")
sentence = " "
while True:
oled.text("{}".format("Magic8PicoBricks"), 0, 30)
oled.show()
if (pin_button.value()) == (1):
sentence = situation[random.randint(0, (len(situation)) - (1))] oled.fill(0)
oled.show()
pin_led.on()
for i in range((4)):
oled.fill(0)
oled.text("{}".format((4) - i), 60, 30)
oled.show()
time.sleep((1))
oled.fill(0)
if (len(sentence)) >= (16):
sentence_array = sentence.split(blank)
for i in range((1) + (len(sentence_array))):
oled.text("{}".format(sentence_array[i - (1)]), 32, (10) * (i - (1)))
oled.show()
else:
oled.fill(0)
oled.text("{}".format(sentence), 0, 25)
oled.show()
time.sleep((3))
pin_led.off()
oled.fill(0)
oled.show()
</code></pre>
Arduino C Codes of PicoBricks
//define the library
#include
#include “ACROBOTIC_SSD1306.h”
#define BUTTON_PIN 10
#define DHTPIN 11
const char* sentences[] = {
“It is certain.”,
“It is decidedly so.”,
“Without a doubt.”,
“Yes definitely.”,
“You may rely on it.”,
“As I see it, yes.”,
“Most likely.”,
“Outlook good.”,
“Yes.”,
“Signs point to yes.”,
“Reply hazy, try again.”,
“Ask again later.”,
“Better not tell you now.”,
“Cannot predict now.”,
“Concentrate and ask again.”,
“Don’t count on it.”,
“My reply is no.”,
“My sources say no.”,
“Outlook not so good.”,
“Very doubtful.”
};
const int numSentences = sizeof(sentences) / sizeof(sentences[0]);
void setup() {
//define dht sensor and Oled screen
pinMode(BUTTON_PIN, INPUT);
Wire.begin();
oled.init();
oled.clearDisplay();
Serial.begin(9600);
}
void loop() {
oled.setTextXY(3, 0);
oled.putString(“Magic8PicoBricks”);
if (digitalRead(BUTTON_PIN) == 1) {
oled.clearDisplay();
for (int i = 3; i > 0; i–) {
oled.clearDisplay();
oled.setTextXY(3, 7);
oled.putString(String(i));
delay(2000);
oled.clearDisplay();
}
oled.clearDisplay();
int randomIndex = random(0, numSentences);
oled.setTextXY(0, 0);
oled.putString(sentences[randomIndex]);
delay(3000);
oled.clearDisplay();
}
}