Skip to content
International Shipping
Wish Lists Cart
0 items

Number Guessing Game

06 Nov 2023
Number Guessing Game

Mystery Number Guessing Game Project!

Table of Contents

    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…

    Guess The Number!

    Details and Algorithm

    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!

    Components

    1X PicoBricks

    Wiring Diagram

    PicoBricks IDE Codes of the PicoBricks

    MicroBlocks Codes of PicoBricks

    MicroPython Codes of the 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
    “`

    Arduino Codes of the PicoBricks

    #include <Wire.h>
    #include “ACROBOTIC_SSD1306.h”
    #define BUTTON_PIN 10
    #define DHTPIN 11
    //define the library

    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();

      }
    }
     

    You can access other interactive projects like the “Guess the Number Game” here!

     

    
    
    Prev Post
    Next Post

    Thanks for subscribing!

    This email has been registered!

    Shop the look
    Choose Options

    Edit Option

    Have Questions?

    Back In Stock Notification

    Compare

    Product SKUDescription Collection Availability Product Type Other Details

    Terms & Conditions

    What is Lorem Ipsum? Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. Why do we use it? It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).
    this is just a warning
    Login
    Shopping Cart
    0 items