一、背景
- RGB LED:通过红、绿、蓝三种颜色组合发光的LED,可以理解由三个不同发光属性的LED组成,这个是LCD平板显示原理的基础,一个LED相当于屏幕上面的一个像素
- FRDM-MCXN947集成了一块RGB LED,它由三个GPIO口驱动,这里由于GPIO的电平只能是0或者1,所以这里的RGB LED并不能像LCD的单个像素那样合成256x256x256种颜色
二、颜色表
三原色合成颜色关系表如图所示
颜色组合关系表
颜色 | Red | Green | Blue | 英文名 |
---|---|---|---|---|
红 | 1 | 0 | 0 | Red |
绿 | 0 | 1 | 0 | Green |
蓝 | 0 | 0 | 1 | Blue |
品红 | 1 | 0 | 1 | Pink |
黄 | 1 | 1 | 0 | Yellow |
青 | 0 | 1 | 1 | Cyan |
白 | 1 | 1 | 1 | White |
三、电路
电路引脚对应关系:R -> P0_10,G -> P0_27,B -> P1_2
驱动方式:上拉接VCC,通过灌电流方式接入GPIO,低电平发光
四、程序设计
初始化RGB LED
#include "drv_pin.h"#define LEDR_PIN ((0*32)+10)
#define LEDG_PIN ((0*32)+27)
#define LEDB_PIN ((1*32)+2)......{rt_pin_mode(LEDR_PIN, PIN_MODE_OUTPUT); /* Set GPIO as Output */rt_pin_mode(LEDG_PIN, PIN_MODE_OUTPUT); /* Set GPIO as Output */rt_pin_mode(LEDB_PIN, PIN_MODE_OUTPUT); /* Set GPIO as Output */
}
动态展示各种混合颜色
while (1)
{// Redrt_pin_write(LEDR_PIN, PIN_LOW); rt_pin_write(LEDG_PIN, PIN_HIGH); rt_pin_write(LEDB_PIN, PIN_HIGH); rt_thread_mdelay(delay); // Greenrt_pin_write(LEDR_PIN, PIN_HIGH); rt_pin_write(LEDG_PIN, PIN_LOW); rt_pin_write(LEDB_PIN, PIN_HIGH); rt_thread_mdelay(delay); // Bluert_pin_write(LEDR_PIN, PIN_HIGH); rt_pin_write(LEDG_PIN, PIN_HIGH); rt_pin_write(LEDB_PIN, PIN_LOW); rt_thread_mdelay(delay); // Yellowrt_pin_write(LEDR_PIN, PIN_LOW); rt_pin_write(LEDG_PIN, PIN_LOW); rt_pin_write(LEDB_PIN, PIN_HIGH); rt_thread_mdelay(delay); // Pinkrt_pin_write(LEDR_PIN, PIN_LOW); rt_pin_write(LEDG_PIN, PIN_HIGH); rt_pin_write(LEDB_PIN, PIN_LOW); rt_thread_mdelay(delay); // Cyanrt_pin_write(LEDR_PIN, PIN_HIGH); rt_pin_write(LEDG_PIN, PIN_LOW); rt_pin_write(LEDB_PIN, PIN_LOW); rt_thread_mdelay(delay); // Whitert_pin_write(LEDR_PIN, PIN_LOW); rt_pin_write(LEDG_PIN, PIN_LOW); rt_pin_write(LEDB_PIN, PIN_LOW); rt_thread_mdelay(delay); }
五、总结
纸上得来终觉浅,绝知此事要躬行,曾经在大学学过LCD平板显示原理,知道像素的显示原理,知道三原色,但一直没有机会实操,我也不大清楚青色(cyan)居然由绿色(green)和蓝色(blue)合成的
六、术语
- RGB:red green blue,红色、绿色、蓝色三种颜色的通称
- LED:light emittiing diode,发光二极管
- LCD:Liquid Crystal Display,液晶显示
- pink:品红、粉红
- cyan:青色