当前位置:网站首页>Raspberry Pie: two color LED lamp experiment
Raspberry Pie: two color LED lamp experiment
2022-04-23 07:22:00 【Lin Jinpeng】
Raspberry pie : Two colors LED Lamp experiment
brief introduction
Two colors LED The lamp ( Double primary color LED The lamp ), Means that the module can only display 2 Color , Usually red and green , There can be three states : destroy 、 Color 1 bright 、 Color 2 bright ; Depending on the color combination , Divided into red and blue , Yellow and blue , Red and green, etc .
Two colors LED Often used to indicate the State : For example, red indicates that the device is abnormal , Green means normal .
One 、 Experimental results
Raspberry pie : Two colors LED Lamp experiment
Two 、 Components
1、 Raspberry pie motherboard *1
2、 Raspberry pie power *1
3、40P ffc *1
4、 Two colors LED modular *1
5、 Breadboard *1
6、 Several jumpers
3、 ... and 、 Experimental principle
Insert the pin S( green ) And the middle pin R( Red ) Connected to raspberry pie GPO On the interface , Programming raspberry pie , take LED The color changes from red to green , And then use PWM Mix other colors .
The schematic diagram of the module is as follows :
Four 、 The experimental steps
Build a circuit :
Raspberry pie | Breadboard | Two colors LED modular |
---|---|---|
GPIO1 | GPIO18 | G(S) |
GPIO0 | GPIO17 | R( middle ) |
GND | GND | GND |
5、 ... and 、 Code implementation
WM The frequency of :P Determines the output digital signal on (1) and off(0 ) Switching speed of , The higher the frequency is. , The faster you switch .
Duty cycle : It refers to... In a series of ideal pulses , The ratio of the duration of the positive pulse to the total period of the pulse , Used to adjust the brightness of the lamp .
import RPi.GPIO as GPIO
import time
colors = [0xFF00, 0x00FF, 0x0FF0, 0xF00F]
makerobo_pins = (11, 12) # PIN Pin dictionary
GPIO.setmode(GPIO.BOARD) # Use actual physical pins to GPIO mouth
GPIO.setwarnings(False) # Remove GPIO Mouth warning
GPIO.setup(makerobo_pins, GPIO.OUT) # Set up Pin The mode is output mode
GPIO.output(makerobo_pins, GPIO.LOW) # Set up Pin The pin is low level (0V) close LED
p_R = GPIO.PWM(makerobo_pins[0], 2000) # Set the frequency to 2KHz
p_G = GPIO.PWM(makerobo_pins[1], 2000) # Set the frequency to 2KHz
# The initialization duty cycle is 0(led close )
p_R.start(0)
p_G.start(0)
def makerobo_pwm_map(x, in_min, in_max, out_min, out_max):
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min
def makerobo_set_Color(col): # for example :col = 0x1122
R_val = col >> 8
G_val = col & 0x00FF
# hold 0-255 The scope of is reduced to 0-100 Between
R_val = makerobo_pwm_map(R_val, 0, 255, 0, 100)
G_val = makerobo_pwm_map(G_val, 0, 255, 0, 100)
p_R.ChangeDutyCycle(R_val) # Change the duty cycle
p_G.ChangeDutyCycle(G_val) # Change the duty cycle
# Call the loop function
def makerobo_loop():
while True:
for col in colors:
makerobo_set_Color(col)
time.sleep(0.5)
# Release resources
def makerobo_destroy():
p_G.stop()
p_R.stop()
GPIO.output(makerobo_pins, GPIO.LOW) # Close all LED
GPIO.cleanup() # Release resources
# Program entrance
if __name__ == "__main__":
try:
makerobo_loop() # Call the loop function
except KeyboardInterrupt: # When pressed Ctrl+C when , Will perform destroy() Subroutines .
makerobo_destroy() # Release resources
版权声明
本文为[Lin Jinpeng]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230609473105.html
边栏推荐
- 【动态规划】最长递增子序列
- Bottom navigation bar based on bottomnavigationview
- 【点云系列】 A Rotation-Invariant Framework for Deep Point Cloud Analysis
- 【点云系列】Pointfilter: Point Cloud Filtering via Encoder-Decoder Modeling
- torch_geometric学习一,MessagePassing
- 【点云系列】Neural Opacity Point Cloud(NOPC)
- Gephi教程【1】安装
- 【动态规划】不同的二叉搜索树
- ThreadLocal,看我就够了!
- Pymysql connection database
猜你喜欢
机器学习 二:基于鸢尾花(iris)数据集的逻辑回归分类
[2021 book recommendation] kubernetes in production best practices
[2021 book recommendation] practical node red programming
【2021年新书推荐】Practical IoT Hacking
Cancel remote dependency and use local dependency
【点云系列】 A Rotation-Invariant Framework for Deep Point Cloud Analysis
图像分类白盒对抗攻击技术总结
SSL/TLS应用示例
第1章 NumPy基础
【点云系列】点云隐式表达相关论文概要
随机推荐
Machine learning notes 1: learning ideas
What did you do during the internship
Kotlin征途之data class [数据类]
第2章 Pytorch基础1
c语言编写一个猜数字游戏编写
第1章 NumPy基础
1.2 初试PyTorch神经网络
【2021年新书推荐】Practical Node-RED Programming
adb shell常用模拟按键keycode
[2021 book recommendation] red hat rhcsa 8 cert Guide: ex200
Ffmpeg common commands
[dynamic programming] different paths 2
Viewpager2 realizes Gallery effect. After notifydatasetchanged, pagetransformer displays abnormal interface deformation
【動態規劃】不同路徑2
Five methods are used to obtain the parameters and calculation of torch network model
WebRTC ICE candidate里面的raddr和rport表示什么?
读书小记——Activity
【点云系列】 A Rotation-Invariant Framework for Deep Point Cloud Analysis
C language, a number guessing game
【动态规划】最长递增子序列