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
76
'''
Use the Threading module to create threads, inherit directly from threading.Thread, and
then override the __init__ method and the run method
'''
class RobotLight(threading.Thread):
def __init__(self, *args, **kwargs):
'''
Here initialize some settings about LED lights
'''
self.LED_COUNT = 16 # Number of LED pixels.
self.LED_PIN = 12 # GPIO pin connected to the pixels (18 uses PWM!).
self.LED_FREQ_HZ = 800000 # LED signal frequency in hertz (usually 800khz)
self.LED_DMA = 10 # DMA channel to use for generating signal (try 10)
self.LED_BRIGHTNESS = 255 # Set to 0 for darkest and 255 for brightest
self.LED_INVERT = False # True to invert the signal (when using NPN transistor
level shift)
self.LED_CHANNEL = 0 # set to '1' for GPIOs 13, 19, 41, 45 or 53
'''
Set the brightness of the three RGB color channels, no need to change here, these
values will be automatically set after the subsequent call of the breathing light function
'''
self.colorBreathR = 0
self.colorBreathG = 0
self.colorBreathB = 0
self.breathSteps = 10
'''
The mode variable, 'none' will make the thread block and hang, the light will not
change;
'police' is a police light mode, red and blue flash alternately;
'breath' breathing light, you can set the specified color.
'''
self.lightMode = 'none' #'none' 'police' 'breath'
# Create NeoPixel object with appropriate configuration.
self.strip = Adafruit_NeoPixel(self.LED_COUNT, self.LED_PIN, self.LED_FREQ_HZ,
self.LED_DMA, self.LED_INVERT, self.LED_BRIGHTNESS,
self.LED_CHANNEL)
# Intialize the library (must be called once before other functions).
self.strip.begin()