Tutorial
Table Of Contents
- 1. Premise
- 2. Raspberry Pi System Installation and Developmen
- 3 Log In to The Raspberry Pi and Install The App
- 4 Assembly and Precautions
- 5 Controlling 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 How to Control DC Motor
- 12 Ultrasonic Module
- 13 Line Tracking
- 14 Make A Police Light or Breathing Light
- 15 Real-Time Video Transmission
- 16 Automatic Obstacle Avoidance
- 17 Why OpenCV Uses Multi-threading to Process Vide
- 18 OpenCV Learn to Use OpenCV
- 19 Using OpenCV to Realize Color Recognition and T
- 20 Machine Line Tracking Based on OpenCV
- 21 Create A WiFi Hotspot on The Raspberry Pi
- 22 Install GUI Dependent Item under Window
- 23 How to Use GUI
- 24 Control The WS2812 LED via GUI
- 25 Real-time Video Transmission Based on OpenCV
- 26 Use OpenCV to Process Video Frames on The PC
- 27 Enable UART
- 28 Control Your AWR with An Android Device
- Conclusion
75
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