Skip to content
International Shipping
Wish Lists Cart
0 items

Labyrinth Game

06 Nov 2023
Labyrinth Game

Table of Contents

    Your imagination is the limit of what you can do with PicoBricks!

    With PicoBricks, you can create most games you want using your creativity. For example, making labyrinth games can be pretty fun. With the new version PicoBricks, you can control it with a remote control! 

    If we need to talk about the maze game and how it should be played; players have ability to control the movement of the ball’s movement with a remote control or comparable device, with the goal of reaching a hole or target point. As they navigate through the maze game, players maintain the ball’s balance and overcome obstacles, all while aiming to expertly guide the ball to its destination. The maze game demand focus, hand-eye coordination, and patience, providing players with an immersive and rewarding experience.

    Details and Algorithm

    We’ve specifically crafted the labyrinth game to offer wireless control over a servo motor using PicoBricks and an IR receiver. Our program is engineered to spot signals sent from an IR remote control and then instruct the servo motor to perform various actions such as moving up, down, left, right, or stopping—based on these signals. 

    We’ve meticulously calculated the servo motor’s angles and translated them into precise positions by employing a PWM (Pulse Width Modulation) signal. Our program not only serves as a fundamental example for automation projects and remote-controlled devices but also includes a mechanical design generated through a 3D printer. Those interested can delve into the code to gain an in-depth understanding of its functionality and utilize it for similar projects.

    If you prefer, you can create your own maze game and print it on your 3D printer, or you can download the STL file and print it on your 3D printer using the download button below.

    DOWNLOAD

    Wiring Diagram

    MicroBlocks Codes of PicoBricks

    PicoBlockly Codes of PicoBricks

    MicroPython Codes of PicoBricks

    The MicroPython code is shown below. Remember to set the degree and degree2 values when coding, as the servos may be connected differently.

    
    from time import sleep
    from machine import Pin
    from picobricks import NEC_16
    from picobricks import IR_RX
    from machine import PWM
    from math import fabs
    
    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
    
    pwm_2 = PWM(Pin(22))
    pwm_2.freq(50)
    def CalculateAngle(angle):
       angle = fabs((angle * (6000 / 180)) + 2000)
       angle = round(angle)
       return angle
    
    def up():
        global dare_question_long, blank, degree, degree2, i
        for count in range((8)):
            degree += 2
            pwm_2.duty_u16(CalculateAngle(degree))
    
    pwm_1 = PWM(Pin(21))
    pwm_1.freq(50)
    
    def left():
        global dare_question_long, blank, degree, degree2, i
        for count in range((8)):
            degree2 += 2
            pwm_1.duty_u16(CalculateAngle(degree2))
    
    def down():
        global dare_question_long, blank, degree, degree2, i
        for count in range((8)):
            degree -= 2
            pwm_2.duty_u16(CalculateAngle(degree))
    
    def right():
        global dare_question_long, blank, degree, degree2, i
        for count in range((8)):
            degree2 -= 2
            pwm_1.duty_u16(CalculateAngle(degree2))
    
    def stop():
        global dare_question_long, blank, degree, degree2, i
        degree = 0
        degree2 = 0
        pwm_1.duty_u16(CalculateAngle(degree))
        pwm_2.duty_u16(CalculateAngle(degree2))
    
    degree = 60
    degree2 = 60
    i = 0
    
    while True:
        if data_rcvd == True:
            data_rcvd = False
            if ir_data == IR_RX.number_up:
                up()
            elif ir_data == IR_RX.number_down:
                down()
            elif ir_data == IR_RX.number_left:
                left()
            elif ir_data == IR_RX.number_right:
                right()
            elif ir_data == IR_RX.number_ok:
                stop()
    

    Arduino C Codes of PicoBricks

    
    #include <Wire.h>
    #include <DHT.h>
    #include "ACROBOTIC_SSD1306.h"
    #include <IRremote.h>
    #include <IRremote.hpp>
    #include <Servo.h>
    #define IR_RECEIVE_PIN 0
    Servo servo1;
    Servo servo2;
    int angle1, angle2;
    void servoBalance(){
      angle1 = 90; // set the horizontal plane angle 
      angle2 = 90; 
      setServoAngle();
    }
    void setServoAngle(){
      servo1.write(angle1);
      servo2.write(angle2);
    }
    void setup() {
      Serial.begin(9600);
      Wire.begin();  
      oled.init();                      
      oled.clearDisplay(); 
      pinMode(0,INPUT);
      IrReceiver.begin(IR_RECEIVE_PIN, ENABLE_LED_FEEDBACK);
      servo1.attach(21); 
      servo2.attach(22);
      servoBalance();
    }
    void loop() {
      setServoAngle();
      delay(500);
      if (IrReceiver.decode()) {
        int a = (IrReceiver.decodedIRData.decodedRawData);
        Serial.println(a);
        IrReceiver.resume(); // Receive the next value
        if(a == -417792256){
           angle2+=30;
        }else if (a == -1387069696){
           angle2-=30;
        }else if (a == -150405376){
           angle1-=30; 
        }else if (a == -1520763136){
           angle1+=30;
        }else if (a == -484638976){
           servoBalance();
        }
      }
    }
    
    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