600字范文,内容丰富有趣,生活中的好帮手!
600字范文 > 二 树莓派RGB LED实验

二 树莓派RGB LED实验

时间:2023-01-28 11:35:18

相关推荐

二 树莓派RGB LED实验

注:本文只做记录,参考。缺乏详细记录,但有疑问可以留言。

RGB LED模块可以发出各种颜色的光。红色,绿色和蓝色的三个LED被封装到透明或半透明塑料外壳中,并带有四个引脚。红色,绿色和蓝色三原色可以按照亮度混合并组合各种颜色,因此可以通过控制电路使RGB LED发出彩色光。

接线:

将树莓派通过T型转接板连接到面包板。

树莓派GPIO 11,“红白线”连接RGB LED模块R端子;

树莓派GPIO 12,“绿白线”连接RGB LED模块G端子;

树莓派GPIO 13 ,“蓝白线”连接RGB LED模块B端子;

树莓派GND,“黑线”连接RGB LED模块GND端子。

效果图:

C语言程序:

#include <wiringPi.h>#include <softPwm.h>#include <stdio.h>#define uchar unsigned char#define makerobo_Led_PinRed 0 // 红色LED 管脚#define makerobo_Led_PinGreen 1 // 绿色LED 管脚#define makerobo_Led_PinBlue 2 // 蓝色LED 管脚// LED 初始化void makerobo_led_Init(void){softPwmCreate(makerobo_Led_PinRed, 0, 100);softPwmCreate(makerobo_Led_PinGreen,0, 100);softPwmCreate(makerobo_Led_PinBlue, 0, 100);}// LED 颜色设置void makerobo_led_Color_Set(uchar r_val, uchar g_val, uchar b_val){softPwmWrite(makerobo_Led_PinRed, r_val);softPwmWrite(makerobo_Led_PinGreen, g_val);softPwmWrite(makerobo_Led_PinBlue, b_val);}//-------------主程序-----------------int main(void){//初始化连接失败时,将消息打印到屏幕if(wiringPiSetup() == -1){printf("setup wiringPi failed !");return 1; }makerobo_led_Init();while(1){makerobo_led_Color_Set(0xff,0x00,0x00); // 红色delay(500); // 延时500msmakerobo_led_Color_Set(0x00,0xff,0x00); // 绿色delay(500); // 延时500msmakerobo_led_Color_Set(0x00,0x00,0xff); // 蓝色delay(500);makerobo_led_Color_Set(0xff,0xff,0x00); //黄色delay(500); // 延时500msmakerobo_led_Color_Set(0xff,0x00,0xff); //pickdelay(500); // 延时500msmakerobo_led_Color_Set(0xc0,0xff,0x3e);delay(500); // 延时500msmakerobo_led_Color_Set(0x94,0x00,0xd3);delay(500);makerobo_led_Color_Set(0x76,0xee,0x00);delay(500);makerobo_led_Color_Set(0x00,0xc5,0xcd);delay(500);}return 0;}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。