One of your favorite childhood memories is probably playing rock paper scissors game with your friends. This simple yet exciting game has maintained its popularity over the years, bringing friends together and creating lasting memories!
Rock Paper Scissors Game
This software revives the game of rock paper scissors in a modern way. With PicoBricks, it transforms players’ choices into a fun experience with visual and sound effects. The game is full of excitement with a random choice that leads to a different outcome each time. Are you ready to have fun? Immerse yourself in the magical world of rock, paper, scissors with “Rock, Paper, Scissors”, play it with PicoBricks and enjoy the game with just one click!
How to Play Rock Paper Scissors?
Details and Algorithm
How to Play Rock Paper Scissors? We initiate the project by setting up fundamental hardware elements: a buzzer, OLED display, and servo motor, laying the groundwork for our endeavor. Our game logic and sound effects are thoughtfully organized into distinct functions: RPS(), music(), and Starter(). The computer randomly opts for Rock, Paper, or Scissors, eventually revealing its selection through animated visuals and corresponding sound effects on the OLED screen. The arrow that moves with the servo indicates what the computer chose in rock paper scissors.
This harmonious fusion of hardware and software culminates in an interactive rendition of the timeless rock-paper-scissors game, offering an immersive experience enjoyable for individuals of all ages.
Components
1X PicoBricks
1X Servo Motor
Wiring Diagram
MicroBlocks Codes of the PicoBricks
MicroPython Codes of the PicoBricks
The Micro Python code is shown below. You will need to create a separate Python file for your image files. You can download this file using the button below.
#include <IRremote.h>
#include <Wire.h>
#include "ACROBOTIC_SSD1306.h"
#define IR_RECEIVE_PIN 0
#define trigPin 15
#define echoPin 14
int a = 0;
long duration, distance;
void setup() {
//define dht sensor and Oled screen
Serial.begin(115200);
Wire.begin();
oled.init();
oled.clearDisplay();
pinMode(IR_RECEIVE_PIN, INPUT);
IrReceiver.begin(IR_RECEIVE_PIN, ENABLE_LED_FEEDBACK);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
}
void loop() {
if (IrReceiver.decode()) {
a = (IrReceiver.decodedIRData.decodedRawData);
Serial.println(a);
IrReceiver.resume();
}
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration / 2) / 29.1;
if (distance <= 10)
{
stop();
}
if (a == -1520763136) {
left();
}
if (a == -150405376) {
right();
}
if (a == -417792256) {
forward();
}
if (a == -484638976) {
stop();
}
}
void stop()
{
digitalWrite(21, LOW);
digitalWrite(22, LOW);
}
void left()
{
digitalWrite(21, HIGH);
digitalWrite(22, LOW);
}
void right()
{
digitalWrite(21, LOW);
digitalWrite(22, HIGH);
}
void forward()
{
digitalWrite(21, HIGH);
digitalWrite(22, HIGH);
}
PicoBricks IDE Codes of the PicoBricks
Arduino C Codes of the PicoBricks
DOWNLOAD
from machine import I2C, Pin, SPI, PWM, ADC
from utime import sleep
from picobricks import SSD1306_I2C, WS2812
import framebuf
import random
from rps_images import rock,paper,scissors,start, Tones, win_song, time_song, loading
WIDTH = 128 # oled display width
HEIGHT = 64 # oled display height
servo = PWM(Pin(21))
i2c = I2C(0, scl=Pin(5), sda=Pin(4), freq=200000) # Init I2C using pins(default I2C0 pins)
oled = SSD1306_I2C(WIDTH, HEIGHT, i2c, addr=0x3c) # Init oled display
ws2812 = WS2812(13,6,brightness=1)
fb1 = framebuf.FrameBuffer(rock, 128,64 , framebuf.MONO_HLSB)
fb2 = framebuf.FrameBuffer(paper, 128,64, framebuf.MONO_HLSB)
fb3 = framebuf.FrameBuffer(scissors, 128,64, framebuf.MONO_HLSB)
loading = framebuf.FrameBuffer(loading, 128,64, framebuf.MONO_HLSB)
start = framebuf.FrameBuffer(start, 128,64, framebuf.MONO_HLSB)
buzzer = PWM(Pin(20))
buzzer.duty_u16(0)
button = Pin(10, Pin.IN)
oled = SSD1306_I2C(WIDTH, HEIGHT, i2c, addr=0x3c) # Init oled display
oledVisuals = [fb1, fb2, fb3]
servoPositions = [8500, 5500, 3500]
RED = (255, 0, 0)
BLUE =(0, 0, 255)
GREEN = (0, 255, 0)
BLACK = (0, 0, 0)
ORANGE = (255, 100, 0)
resultColors = [RED, BLUE, GREEN]
analog_value = ADC(28)
def neo():
for i in range(0,13):
ws2812.pixels_fill((random.randint(0,255),
random.randint(0,255),
random.randint(0,255)))
sleep(0.05)
ws2812.pixels_show()
def winningSound():
for note, duration in win_song:
buzzer.freq(Tones[note])
buzzer.duty_u16(5000)
sleep(duration*0.1)
buzzer.duty_u16(0)
sleep(duration*0.1)
def timesong():
for note, duration in time_song:
buzzer.freq(Tones[note])
buzzer.duty_u16(5000)
sleep(duration*0.07)
buzzer.duty_u16(0)
sleep(duration*0.07)
def Sweep(i):
servo.freq(50)
ws2812.pixels_fill((random.randint(0,255),
random.randint(0,255),
random.randint(0,255)))
ws2812.pixels_show()
for position in range(4000,8000,500):
servo.duty_u16(position)
sleep(0.01)
for position in range(8000,4000,-500):
servo.duty_u16(position)
sleep(0.01)
oled.fill(0)
oled.blit(oledVisuals[i], 0, 0)
oled.show()
timesong()
random.seed(analog_value.read_u16())
while True:
if button.value() == 1:
servo.freq(50)
servo.duty_u16(5500)
sleep(0.01)
oled.blit(loading, 0, 0)
oled.show()
sleep(1)
oled.fill(0)
result = random.randint(0,2)
for i in range(3):
Sweep(i)
sleep(0.1)
servo.freq(50)
servo.duty_u16(servoPositions[result])
oled.blit(oledVisuals[result], 0, 0)
oled.show()
ws2812.pixels_fill((random.randint(0,255),
random.randint(0,255),
random.randint(0,255)))
ws2812.pixels_show()
winningSound()
sleep(2)
print(servoPositions[result])
print(result)
else:
servo.freq(50)
servo.duty_u16(2000)
oled.blit(start, 0, 0)
oled.show()
ws2812.pixels_fill(ORANGE)
ws2812.pixels_show()
You can click here to experience PicoBricks on the simulator!