一、RGB灯
RGB灯有4个引脚,R、G、B三个引脚连接到LED的一端,还有一个引脚是共用的正极或者共用的阴极。 共阴显示红色:R-255,G-0,B-0 共阳显示红色:R-0,G-255,B-255
二、示例
#include<Arduino.h>
uint8_t ledR = 27;
uint8_t ledG = 26;
uint8_t ledB = 25;
void setup()
{
Serial.begin(115200);
delay(10);
ledcAttachPin(ledR, 1);
ledcAttachPin(ledG, 2);
ledcAttachPin(ledB, 3);
ledcSetup(1, 12000, 8);
ledcSetup(2, 12000, 8);
ledcSetup(3, 12000, 8);
}
void loop()
{
ledcWrite(1, 0);
ledcWrite(2, 255);
ledcWrite(3, 255);
delay(2000);
ledcWrite(1, 255);
ledcWrite(2, 0);
ledcWrite(3, 255);
delay(2000);
ledcWrite(1, 255);
ledcWrite(2, 255);
ledcWrite(3, 0);
delay(2000);
}
|