We always say to our friends, “Let’s guess the number.” You’ve probably heard the answers: “No, it’s bigger. No, it’s smaller. Wow, how did you know?” Wouldn’t you like to do just that with PicoBricks? We invite you to a journey full of mathematics and intelligence! Today we open the door to an exciting project: the number guessing game project.
This project is a fun experience designed to test your math skills, improve problem-solving skills, and hone your mental abilities.
The guess the number game is a fun and interactive coding project that challenges players to guess a random number within a specified range. This number guessing game project not only sharpens your programming skills but also offers an entertaining experience for players as they attempt to guess the correct number. Whether you’re a beginner looking to learn coding or an enthusiast seeking an engaging game development project, Guess The Number Game is a great choice to explore and enjoy.
Remember, you will learn much more than just to guess the number in this project…
Press the “Start” button to start the number guessing game. To update your forecast, follow the steps below. If the player presses the up arrow key from remote (if the picobrick estimate is less than the number the player selected), the estimated range is halved again and that value is added to the current picobrick estimate.
If the player presses the down arrow key from remote (if the picobrick estimate is greater than the number selected by the player), the estimated range is halved again and that value is subtracted from the current picobricks estimate. When the player presses the “OK” button from remote, the number guessing game ends and PicoBricks celebrates. This means that the number chosen by the player was guessed correctly!
1X PicoBricks
`
“`
from time import sleep
from machine import Pin
from machine import I2C
from picobricks import SSD1306_I2C
import machine
from picobricks import NEC_16
from picobricks import IR_RX
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)
def ir_callback(data, addr, ctrl):
global ir_data
global ir_addr, data_rcvd
if data > 0:
ir_data = data
ir_addr = addr
print(‘Data {:02x} Addr {:04x}’.format(data, addr))
data_rcvd = True
ir = NEC_16(Pin(0, Pin.IN), ir_callback)
ir_data = 0
data_rcvd = False
def up():
global i_g, n_r
i_g += n_r
oled.fill(0)
oled.text(“{}”.format(str(“My gues:”)+str(i_g)), 0, 0)
oled.show()
n_r = int(n_r / (2))
time.sleep((0.5))
def ok():
global i_g, n_r
oled.fill(0)
oled.text(“{}”.format(str(“Your number”)+str(i_g)), 0, 0)
oled.text(“{}”.format(“Congratulations Picobricks “), 15, 32)
oled.show()
time.sleep((0.5))
def down():
global i_g, n_r
i_g += (0) – n_r
if i_g < (0):
i_g = 0
else:
oled.fill(0)
oled.text(“{}”.format(str(“My gues:”)+str(i_g)), 0, 0)
oled.show()
n_r = int(n_r / (2))
time.sleep((0.5))
oled.fill(0)
oled.text(“{}”.format(“Press the Button “), 0, 20)
oled.text(“{}”.format(“TO START!!!”), 15, 30)
oled.show()
while (pin_button.value()) == (0):
pass
while True:
oled.fill(0)
n_r = 64
i_g = n_r
oled.text(“{}”.format(str(“My gues:”)+str(i_g)), 25, 0)
oled.text(“{}”.format(“Press \’ok\’ if I guess correctly”), 0, 30)
oled.show()
while True:
if data_rcvd == True:
data_rcvd = False
if ir_data == IR_RX.number_up:
up()
if ir_data == IR_RX.number_down:
down()
if ir_data == IR_RX.number_ok:
ok()
break
“`
You can access other interactive projects like the “Guess the Number Game” here!
Thanks for subscribing!
This email has been registered!
Edit Option
Back In Stock Notification
Compare
Product | SKU | Description | Collection | Availability | Product Type | Other Details |
---|
Terms & Conditions