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.
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.
DOWNLOADThe 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()
#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();
}
}
}
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