Skip to content
International Shipping
Wish Lists Cart
0 items

#10 Know Your Color Project With PicoBricks

19 Nov 2023
#10 Know Your Color Project With PicoBricks

LEDs are often used on electronic systems. Each button can have small LEDs next to each option. By making a single LED light up in different colors, it is possible to do the work of more than one LED with a single LED. LEDs working in this type are called RGB LEDs. It takes its name from the initials of the color names Red, Green, Blue. Another advantage of this LED is that it can light up in mixtures of 3 primary colors. Purple, turquoise, orange…

In this project you will learn about the randomness used in every programming language. We will prepare a enjoyable game with the RGB LED, OLED screen and button module of Picobricks.

In this project, we will create a timer alarm that adjusts for daylight using the light sensor in Picobricks.

Details and Algorithm

The game we will build in the project will be built on the user knowing the colors correctly or incorrectly. One of the colors red, green, blue and white will light up randomly on the RGB LED on Picobricks, and the name of one of these four colors will be written randomly on the OLED screen at the same time. The user must press the button of Picobricks within 1.5 seconds to use the right of reply. The game will be repeated 10 times, each repetition will get 10 points if the user presses the button when the colors match, or if the user does not press the button when they do not match. If the user presses the button even though the colors do not match, he will lose 10 points. After ten repetitions, the user’s score will be displayed on the OLED screen. If the user wishes, he may not use his right of reply by not pressing the button.


1X PicoBricks

Wiring Diagram

You can code and run Picobricks’ modules without wiring. If you are going to use the modules by separating them from the board, you should make the module connections with grove cables.

MicroBlocks Codes of the PicoBricks

You can access the Microblocks codes of the project by dragging the image to the Microblocks Run tab or click the button.


Microblocks Run Tab

MicroPython Codes of the PicoBricks


from machine import Pin,I2C,ADC,PWM  #to access the hardware on the pico
from picobricks importSSD1306_I2C  #OLED Screen Library
import utime
from picobricks importWS2812   #ws8212 library

#OLED Screen Settings

#initialize digital pin 4 and 5as an OUTPUTforOLED Communication

i2c=machine.I2C(0,sda=sda, scl=scl, freq=1000000)
neo =WS2812(pin_num=6, num_leds=1, brightness=0.3)#initialize digital pin 6as an OUTPUTfor NeoPixel

oled =SSD1306_I2C(128,64, i2c)
ldr =ADC(Pin(27))#initialize digital pin 6as an OUTPUTfor NeoPixel
button =Pin(10,Pin.IN,Pin.PULL_DOWN)#initialize digital pin 10as an INPUTfor button
buzzer =PWM(Pin(20, Pin.OUT))#initialize digital pin 20as an OUTPUTfor buzzer
#RGB black and white color code

neo.pixels_show()if ldr.read_u16()<4000:
    wakeup = True
    wakeup = False

while True:while wakeup==False:
        oled.text("Good night",25,32)
        #Show on OLED and print "Good night"
        utime.sleep(1)if ldr.read_u16()40000:
        wakeup= False

    #wait for one second

Arduino C Codes of the PicoBricks


from machine import Pin,I2Cfrom picobricks importSSD1306_I2Cimport utime
import urandom
import _thread
from picobricks importWS2812WIDTH=128HEIGHT=64
i2c=machine.I2C(0,sda=sda, scl=scl, freq=1000000)
ws =WS2812(pin_num=6, num_leds=1, brightness=0.3)

oled =SSD1306_I2C(WIDTH,HEIGHT, i2c)

button =Pin(10,Pin.IN,Pin.PULL_DOWN)RED=(255,0,0)GREEN=(0,255,0)BLUE=(0,0,255)WHITE=(255,255,255)BLACK=(0,0,0)



global button_pressed
button_pressed = False

def random_rgb():
    global ledcolor
    ledcolor=int(urandom.uniform(1,4))if ledcolor ==1:
    elif ledcolor ==2:
    elif ledcolor ==3:
    elif ledcolor ==4:

def random_text():
    global oledtext
    oledtext=int(urandom.uniform(1,4))if oledtext ==1:
    elif oledtext ==2:
    elif oledtext ==3:
    elif oledtext ==4:

def button_reader_thread():while True:
        global button_pressed
        if button_pressed == False:if button.value()==1:
                button_pressed = True
                global score
                global oledtext
                global ledcolor
                if ledcolor == oledtext:
                    score +=10else:
                    score -=10


oled.text("The Game Begins",0,10)
utime.sleep(2)for i inrange(10):for j inrange(10):random_text()random_rgb()
oled.text("Your total score:",0,20)

GitHub Project Page


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


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
Shopping Cart
0 items