Welcome to CUBE Pi Case repository
当製品の日本語版マニュアル資料は、こちらからご取得ください。
RGB light strip driver
Driving the light bar
Driving the light bar1. Learning objectives2. Preparation before the experiment3. Use CubeRaspberry driver library to control RGB light strip1. Import CubeRaspberry driver library and create objects2. Set RGB light effects3. Set the speed of RGB light effects4. Set the color of RGB light effects5. Set the color of a single RGB light6. Code demonstration4. Use Jupyter lab to control the RGB light strip1. Import the CubeRaspberry driver library and create an object2. Set RGB light effects3. Set the speed of RGB light effects4. Set the color of RGB light effects5. Set the color of a single RGB light6. Delete the object7. Code demonstration8. Basic operation of Jupyter lab5. Experimental phenomenon
1. Learning objectives
- Master the control of RGB light bar by Raspberry Pi series motherboard
- Use CubeRaspberry driver library to control RGB light bar
- Control RGB light bar through Jupyter lab
2. Preparation before the experiment
Install the Raspberry Pi chassis according to the assembly video tutorial. You can also refer to the "Raspberry Pi chassis_hardware wiring" tutorial document for installation. Here, the chassis expansion board and RGB light bar and fan hardware connection are shown.

| Chassis expansion board | 3Pin interface | 2Pin interface |
|---|---|---|
| RGB light strip | Fan |
3. Use CubeRaspberry driver library to control RGB light strip
1. Import CubeRaspberry driver library and create objects
The name of the CubeRaspberry driver library is CubeRaspberryLib. Use CubeRaspberryLib to import the library in the program.
xxxxxxxxxxfrom CubeRaspberryLib import CubeRaspberry
CubeRaspberryLib library functions needed to control RGB light strips:
xxxxxxxxxxset_RGB_Effect(effect) #Set RGB light effectsset_RGB_Speed(speed) #Set RGB light effects speedset_RGB_Color(color) #Set RGB light effects colorset_Single_Color(index, r, g, b) #Set single RGB light color
2. Set RGB light effects
| set_RGB_Effect(effect): Set RGB light effects | | :-------------------------------------------------: |
| effect value | RGB light effects |
|---|---|
| 0 | Turn off effects |
| 1 | Monochrome breathing light |
| 2 | Marquee |
| 3 | Rainbow light |
| 4 | Colorful light |
| 5 | Flowing light |
| 6 | Circular breathing light |
3. Set the speed of RGB light effects
| set_RGB_Speed(speed): Set the speed of RGB light effects | | :-------------------------------------: |
| speed value | RGB light effect speed |
|---|---|
| 1 | Low speed |
| 2 | Medium speed |
| 3 | Fast |
4. Set the color of RGB light effects
Note: This function can only be used to set the effect for single-color breathing lights and flowing lights.
| set_RGB_Color(color): Set the RGB light effect color | | :-------------------------------------: |
| color value | RGB light effect color |
|---|---|
| 0 | Red |
| 1 | Green |
| 2 | Blue |
| 3 | Yellow |
| 4 | Purple |
| 5 | Cyan |
| 6 | White |
5. Set the color of a single RGB light
Note: All colors can be composed of different brightness levels of red, green and blue;
| set_Single_Color(index, r, g, b): Set the color of a single RGB light | | :-------------------------------------------------: |
| Parameters | Single RGB light color |
|---|---|
| index | Serial number (0 - 13, 255) |
| r | Red (0 - 255) |
| g | Green (0 - 255) |
| b | Blue (0 - 255) |
Index parameter: 0-13 corresponds to different lamp numbers; index = 255 means setting all RGB lamp colors.
r, g, b parameters: 0-255 represent different color brightness levels.
6. Code demonstration
Control RGB light bar effects and functions (python interactive interface: each statement needs to be run separately)
xxxxxxxxxxfrom CubeRaspberryLib import CubeRaspberrybot = CubeRaspberry(i2c_bus=1) bot.set_RGB_Effect(0) bot.set_RGB_Effect(1) bot.set_RGB_Effect(2) bot.set_RGB_Effect(3) bot.set_RGB_Effect(4) bot.set_RGB_Effect(6) bot.set_RGB_Speed ••(1) bot.set_RGB_Speed(2) bot.set_RGB_Speed(3) bot.set_RGB_Effect(1) bot.set_RGB_Color(0) bot.set_RGB_Color(1) bot.set_RGB_Color(2) bot.set_RGB_Color(3) bot.set_RGB_Color(4) bot.set_RGB_Color(6) bot.set_Single_Color(5,0,0, 255) bot.set_Single_Color(255,255,255,255) del bot

import timefrom CubeRaspberryLib import CubeRaspberryif __name__ == '__main__':bot = CubeRaspberry(i2c_bus=1)while True:bot.set_RGB_Effect(0) # 关闭特效5秒 Turn off the effect for 5 secondstime.sleep(5)bot.set_RGB_Effect(1) # 单色呼吸灯5秒 Monochromatic breathing lamp for 5 sectime.sleep(5)bot.set_RGB_Effect(2) # 跑马灯5秒 Marquee for 5 secondstime.sleep(5)bot.set_RGB_Effect(3) # 彩虹灯5秒 Rainbow lights for 5 secondstime.sleep(5)bot.set_RGB_Effect(4) # 炫彩灯5秒 Dazzle lights for 5 secondstime.sleep(5)bot.set_RGB_Effect(5) # 流水灯5秒 Running water lamp for 5 secondstime.sleep(5)bot.set_RGB_Effect(6) # 循环呼吸灯5秒 Circulate the lamp for 5 sectime.sleep(5)

Note: Press Ctrl + C to terminate the run
4. Use Jupyter lab to control the RGB light strip
In Jupyter Create a new file in the lab interface and create the following code blocks, edit the following contents respectively (Fan_Test.ipynb):
1. Import the CubeRaspberry driver library and create an object
xxxxxxxxxx# Import the CubeRaspberry driver library Import the CubeRaspberry driver libraryfrom CubeRaspberryLib import CubeRaspberry# Create an object Create an objectbot = CubeRaspberry(i2c_bus=1)
2. Set RGB light effects
xxxxxxxxxxbot.set_RGB_Effect(0) # Turn off effects
xxxxxxxxxxbot.set_RGB_Effect(1) # Monochrome breathing light
xxxxxxxxxxbot.set_RGB_Effect(2) # Marquee
xxxxxxxxxxbot.set_RGB_Effect(3) # Rainbow light lights
xxxxxxxxxxbot.set_RGB_Effect(4) # Dazzling lights
xxxxxxxxxxbot.set_RGB_Effect(5) # Running water lamps
xxxxxxxxxxbot.set_RGB_Effect(6) # Circulation breathing lights
3. Set the speed of RGB light effects
xxxxxxxxxxbot.set_RGB_Speed(1) # Low speed
xxxxxxxxxxbot.set_RGB_Speed(2) # Medium speed
xxxxxxxxxxbot.set_RGB_Speed(3) # High speed
4. Set the color of RGB light effects
xxxxxxxxxxbot.set_RGB_Effect(1) # Monochrome breathing light
xxxxxxxxxxbot.set_RGB_Color(0) # red red
xxxxxxxxxxbot.set_RGB_Color(1) # green green
xxxxxxxxxxbot.set_RGB_Color(2) # blue blue
xxxxxxxxxxbot.set_RGB_Color(3) # yellow yellow
xxxxxxxxxxbot.set_RGB_Color(4) # purple purple
xxxxxxxxxxbot.set_RGB_Color(5) # cyan cyan
xxxxxxxxxxbot.set_RGB_Color(6) # white white
5. Set the color of a single RGB light
xxxxxxxxxxbot.set_Single_Color(5,255,0,0) # RGB lights Article 6 lamp beads are displayed in red# RGB lights Article 6 lamp beads are displayed in red red
xxxxxxxxxxbot.set_Single_Color(255,255,255,255) # All RGB beads are shown in white# All RGB beads are shown in white
6. Delete the object
xxxxxxxxxx# Delete the object Delete the objectdel bot
7. Code demonstration


8. Basic operation of Jupyter lab
If you find that the code runs abnormally, it is recommended to follow the steps in the figure and then retest the code block.

5. Experimental phenomenon
Calling the function in the CubeRaspberry driver library can achieve the corresponding phenomenon. Before setting the RGB light effect color and speed, you need to set the RGB light effect first.
For example: After executing the "Set Single RGB Light Color" function, directly using "Set RGB Light Effect Color" will not take effect. You need to first "Set RGB Light Effect 1 or 5" and then "Set RGB Light Effect Color".