下载附件
保存到相册
2022-10-24 15:38 上传
图 35下载附件
保存到相册
2022-10-24 15:38 上传
图 36 blink例程运行结果截图
从代码中中可知采用RMT的通道1,通过IO-MUX连接到GPIO48,观察ESP32-S3-DevKitC,GPIO48在排针上引出,刚好手头有WS2812的LED灯带,接入GPIO48排针引脚,并利用网上的一个比较炫酷的WS2812-LED-Strip光效程序,因略作修改代码后,生成绚丽的颜色,传输到灯带显示,代码如下:
#define LED_COUNTS 32
static uint8_t showType = 0;
void delay(uint8_t n)
{
vTaskDelay(n/portTICK_PERIOD_MS);
}
int numPixels()
{
return LED_COUNTS;
}
void show()
{
pStrip_a->refresh(pStrip_a, 100);
}
void setPixelColor(int led_index, uint32_t c)
{
// WS2812 is in the order of GRB
if(led_index < LED_COUNTS) {
uint8_t g = (uint8_t)(c >> 8 & 0xFF);
uint8_t r = (uint8_t)(c >> 16 & 0xFF);
uint8_t b = (uint8_t)(c >> 0 & 0xFF);
pStrip_a->set_pixel(pStrip_a, led_index, r, g, b);
}
return ;
}
uint32_t Color(uint8_t r, uint8_t g, uint8_t b)
{
uint32_t retVal;
retVal = (( uint32_t)r<< 16)
+ ( (uint32_t)g << 8)
+ (uint32_t)b ;
return retVal;
}
// ======================================================
// Fill the dots one after the other with a color
void colorWipe(uint32_t c, uint8_t wait) {
for(uint16_t i=0; i<numPixels(); i++) {
setPixelColor(i, c);
show();
delay(wait);
}
}
// ======================================================
// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t Wheel(uint8_t WheelPos) {
WheelPos = 255 - WheelPos;
if(WheelPos < 85) {
return Color(255 - WheelPos * 3, 0, WheelPos * 3);
}
if(WheelPos < 170) {
WheelPos -= 85;
return Color(0, WheelPos * 3, 255 - WheelPos * 3);
}
WheelPos -= 170;
return Color(WheelPos * 3, 255 - WheelPos * 3, 0);
}
void rainbow(uint8_t wait) {
uint16_t i, j;
for(j=0; j<256; j++) {
for(i=0; i<numPixels(); i++) {
setPixelColor(i, Wheel((i+j) & 255));
}
show();
delay(wait);
}
}
// Slightly different, this makes the rainbow equally distributed throughout
void rainbowCycle(uint8_t wait) {
uint16_t i, j;
for(j=0; j<256*5; j++) { // 5 cycles of all colors on wheel
for(i=0; i< numPixels(); i++) {
setPixelColor(i, Wheel(((i * 256 / numPixels()) + j) & 255));
}
show();
delay(wait);
}
}
// ======================================================
//Theatre-style crawling lights.
void theaterChase(uint32_t c, uint8_t wait) {
for (int j=0; j<10; j++) { //do 10 cycles of chasing
for (int q=0; q < 3; q++) {
for (int i=0; i < numPixels(); i=i+3) {
setPixelColor(i+q, c); //turn every third pixel on
}
show();
delay(wait);
for (int i=0; i < numPixels(); i=i+3) {
setPixelColor(i+q, 0); //turn every third pixel off
}
}
}
}
//Theatre-style crawling lights with rainbow effect
void theaterChaseRainbow(uint8_t wait) {
for (int j=0; j < 256; j++) { // cycle all 256 colors in the wheel
for (int q=0; q < 3; q++) {
for (int i=0; i < numPixels(); i=i+3) {
setPixelColor(i+q, Wheel( (i+j) % 255)); //turn every third pixel on
}
show();
delay(wait);
for (int i=0; i < numPixels(); i=i+3) {
setPixelColor(i+q, 0); //turn every third pixel off
}
}
}
}
void startShow(int i) {
switch(i){
case 0: colorWipe(Color(0, 0, 0), 50); // Black/off
break;
case 1: colorWipe(Color(255, 0, 0), 50); // Red
break;
case 2: colorWipe(Color(0, 255, 0), 50); // Green
break;
case 3: colorWipe(Color(0, 0, 255), 50); // Blue
break;
case 4: theaterChase(Color(127, 127, 127), 50); // White
break;
case 5: theaterChase(Color(127, 0, 0), 50); // Red
break;
case 6: theaterChase(Color( 0, 0, 127), 50); // Blue
break;
case 7: rainbow(20);
break;
case 8: rainbowCycle(5);
break;
case 9: theaterChaseRainbow(10);
break;
}
}
效果如图/视频
https://www.bilibili.com/video/BV1wN4y157cM/