当前位置:网站首页>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
边栏推荐
- [2021 book recommendation] artistic intelligence for IOT Cookbook
- [多屏互动] 实现双多屏异显二:startActivity方式
- Minesweeping games
- MySQL的安装与配置——详细教程
- 【2021年新书推荐】Kubernetes in Production Best Practices
- Write a wechat double open gadget to your girlfriend
- 【动态规划】最长递增子序列
- [Point Cloud Series] SG - Gan: Adversarial Self - attachment GCN for Point Cloud Topological parts Generation
- How to standardize multidimensional matrix (based on numpy)
- MySQL notes 5_ Operation data
猜你喜欢

【2021年新书推荐】Enterprise Application Development with C# 9 and .NET 5

常用UI控件简写名

【3D形状重建系列】Implicit Functions in Feature Space for 3D Shape Reconstruction and Completion

Chapter 1 numpy Foundation

Binder mechanism principle
![[Point Cloud Series] SG - Gan: Adversarial Self - attachment GCN for Point Cloud Topological parts Generation](/img/1d/92aa044130d8bd86b9ea6c57dc8305.png)
[Point Cloud Series] SG - Gan: Adversarial Self - attachment GCN for Point Cloud Topological parts Generation

【点云系列】点云隐式表达相关论文概要

Bottom navigation bar based on bottomnavigationview

Project, how to package

【点云系列】Relationship-based Point Cloud Completion
随机推荐
[2021 book recommendation] effortless app development with Oracle visual builder
【2021年新书推荐】Practical IoT Hacking
MySQL的安装与配置——详细教程
机器学习 二:基于鸢尾花(iris)数据集的逻辑回归分类
Record WebView shows another empty pit
torch. mm() torch. sparse. mm() torch. bmm() torch. Mul () torch The difference between matmul()
ArcGIS License Server Administrator 无法启动解决方法
红外传感器控制开关
【动态规划】杨辉三角
xcode 编译速度慢的解决办法
如何对多维矩阵进行标准化(基于numpy)
利用官方torch版GCN训练并测试cora数据集
[point cloud series] sg-gan: advantageous self attention GCN for point cloud topological parts generation
Migrating your native/mobile application to Unified Plan/WebRTC 1.0 API
[Andorid] 通过JNI实现kernel与app进行spi通讯
Android暴露组件——被忽略的组件安全
【点云系列】Fully-Convolutional geometric features
Some common data type conversion methods in pytorch are similar to list and NP Conversion method of ndarray
[2021 book recommendation] red hat rhcsa 8 cert Guide: ex200
Compression and acceleration technology of deep learning model (I): parameter pruning