赞
踩
三原色合成颜色关系表如图所示
颜色组合关系表
颜色 | 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) { // Red rt_pin_write(LEDR_PIN, PIN_LOW); rt_pin_write(LEDG_PIN, PIN_HIGH); rt_pin_write(LEDB_PIN, PIN_HIGH); rt_thread_mdelay(delay); // Green rt_pin_write(LEDR_PIN, PIN_HIGH); rt_pin_write(LEDG_PIN, PIN_LOW); rt_pin_write(LEDB_PIN, PIN_HIGH); rt_thread_mdelay(delay); // Blue rt_pin_write(LEDR_PIN, PIN_HIGH); rt_pin_write(LEDG_PIN, PIN_HIGH); rt_pin_write(LEDB_PIN, PIN_LOW); rt_thread_mdelay(delay); // Yellow rt_pin_write(LEDR_PIN, PIN_LOW); rt_pin_write(LEDG_PIN, PIN_LOW); rt_pin_write(LEDB_PIN, PIN_HIGH); rt_thread_mdelay(delay); // Pink rt_pin_write(LEDR_PIN, PIN_LOW); rt_pin_write(LEDG_PIN, PIN_HIGH); rt_pin_write(LEDB_PIN, PIN_LOW); rt_thread_mdelay(delay); // Cyan rt_pin_write(LEDR_PIN, PIN_HIGH); rt_pin_write(LEDG_PIN, PIN_LOW); rt_pin_write(LEDB_PIN, PIN_LOW); rt_thread_mdelay(delay); // White rt_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)合成的
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。