User Manual
Table Of Contents
- 1. Premise
- 2. Raspberry Pi System Installation and Developmen
- 3 Log In to The Raspberry Pi and Install The App
- 4 Raspberry Pi Structure Assembly and Precautions
- 5 Controlling A Robot via WEB App
- 6 Common Problems and Solutions(Q&A)
- 7 Set The Program to Start Automatically
- 8 Remote Operation of Raspberry Pi Via MobaXterm
- 9 How to Control WS2812 RGB LED
- 10 How to Control The Servo
- 11 Calling the API to Control the Robot
- 12 Automatic Stabilization Function
- 13 Gait Generation Method of A Hexapod Robot
- 14 Make A Police Light or Breathing Light
- 15 Real-Time Video Transmission
- 16 Why OpenCV Uses Multi-threading to Process Vide
- 17 OpenCV Learn to Use OpenCV
- 18 Using OpenCV to Realize Color Recognition and T
- 19 Machine Line Tracking Based on OpenCV
- 20 Create A WiFi Hotspot on The Raspberry Pi
- 21 Install GUI Dependent Item under Window
- 22 How to Use GUI
- 23 Enable UART
- 24 Control Your Adeept_RaspClaws with An Android D
- Conclusion
87
14 Make A Police Light or Breathing Light
14.1 Multi-threading Introduction
● This chapter introduces the use of multi-threading to achieve some effects related to WS2812 LED
lights. Multi-threading is a commonly used operation in robot projects. Because robots have high requirements
for real-time response, when performing a certain task, try not to block main thread communication.
● Multi-threading is similar to executing multiple different programs or tasks simultaneously.
Multi-threading has the following advantages:
·Using threads can put long-running tasks in the background for processing.
· To improve the operating efficiency of the program, the subsequent real-time video and OpenCV
processing of video frames use multi-threading to greatly increase the frame rate.
· The encapsulated multi-threaded task is more convenient to call, similar to the 10.3 non-blocking
control method is to use multi-threaded encapsulated control method
●We use Python's threading library to provide thread-related work. Threads are the smallest unit of work
in an application. The current version of Python does not provide multi-thread priority, thread group, and thread
cannot be stopped, suspended, resumed and interrupted.
14.2 Realization of Police Lights / Breathing Lights
●We use the following code to achieve multi-threaded control of LED lights, and when the LED does not
change, keep the thread blocked, so as not to waste CPU resources.
● The wait () method is used here to block the thread, from the realization of the need to control the
thread.
import time
import sys
from rpi_ws281x import *
import threading