当前位置:网站首页>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
边栏推荐
猜你喜欢
Gephi tutorial [1] installation
【2021年新书推荐】Enterprise Application Development with C# 9 and .NET 5
第3章 Pytorch神经网络工具箱
c语言编写一个猜数字游戏编写
【2021年新书推荐】Professional Azure SQL Managed Database Administration
树莓派:双色LED灯实验
【点云系列】Fully-Convolutional geometric features
Pymysql connection database
[Point Cloud Series] SG - Gan: Adversarial Self - attachment GCN for Point Cloud Topological parts Generation
机器学习 二:基于鸢尾花(iris)数据集的逻辑回归分类
随机推荐
Android interview Online Economic encyclopedia [constantly updating...]
常见的正则表达式
torch. mm() torch. sparse. mm() torch. bmm() torch. Mul () torch The difference between matmul()
Component learning (2) arouter principle learning
Viewpager2 realizes Gallery effect. After notifydatasetchanged, pagetransformer displays abnormal interface deformation
MySQL notes 5_ Operation data
HandlerThread原理和实际应用
第3章 Pytorch神经网络工具箱
【点云系列】Fully-Convolutional geometric features
[dynamic programming] different binary search trees
Recyclerview batch update view: notifyitemrangeinserted, notifyitemrangeremoved, notifyitemrangechanged
torch_geometric学习一,MessagePassing
PyTorch训练一个网络的基本流程5步法
Pytorch模型保存与加载(示例)
【2021年新书推荐】Practical Node-RED Programming
Machine learning III: classification prediction based on logistic regression
5种方法获取Torch网络模型参数量计算量等信息
【 planification dynamique】 différentes voies 2
Minesweeping games
Data class of kotlin journey