3098 views|1 replies

660

Posts

1

Resources
The OP
 

ESP32 lighting effects - light up the WS2812 colorful light strip; [Copy link]

 
    1. download attach  save to album

      2022-10-24 15:38 上传

      Figure 3 5download attach  save to album

      2022-10-24 15:38 上传

      Figure 3 6Screenshot of blink routine running results

      From the code, we can see that the channel 1 of RMT is connected to GPIO48 through IO-MUX. Observing ESP32-S3-DevKitC, GPIO48 is brought out on the pin header. I happened to have a WS2812 LED strip on hand, which was connected to the GPIO48 pin header. And using a cool WS2812-LED-Strip light effect program on the Internet, after slightly modifying the code, it generates gorgeous colors and transmits them to the light strip for display. The code is as follows:

      #define LED_COUNTS 32

      staticuint8_tshowType =0;

      voiddelay(uint8_tn)

      {

      vTaskDelay(n/portTICK_PERIOD_MS);

      }

      intnumPixels()

      {

      returnLED_COUNTS;

      }

      voidshow()

      {

      pStrip_a->refresh(pStrip_a,100);

      }

      voidsetPixelColor(intled_index,uint32_tc)

      {

      // WS2812 is in the order of GRB

      if(led_index <LED_COUNTS){

      uint8_tg =(uint8_t)(c >>8&0xFF);

      uint8_tr =(uint8_t)(c >>16&0xFF);

      uint8_tb =(uint8_t)(c >>0&0xFF);

      pStrip_a->set_pixel(pStrip_a,led_index,r,g,b);

      }

      return;

      }

      uint32_tColor(uint8_tr,uint8_tg,uint8_tb)

      {

      uint32_tretVal;

      retVal =((uint32_t)r<<16)

      +((uint32_t)g <<8)

      +(uint32_t)b ;

      returnretVal;

      }

      // ======================================================

      // Fill the dots one after the other with a color

      voidcolorWipe(uint32_tc,uint8_twait){

      for(uint16_ti=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_tWheel(uint8_tWheelPos){

      WheelPos =255-WheelPos;

      if(WheelPos <85){

      returnColor(255-WheelPos *3,0,WheelPos *3);

      }

      if(WheelPos <170){

      WheelPos -=85;

      returnColor(0,WheelPos *3,255-WheelPos *3);

      }

      WheelPos -=170;

      returnColor(WheelPos *3,255-WheelPos *3,0);

      }

      voidrainbow(uint8_twait){

      uint16_ti,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

      voidrainbowCycle(uint8_twait){

      uint16_ti,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.

      voidtheaterChase(uint32_tc,uint8_twait){

      for(intj=0;j<10;j++){//do 10 cycles of chasing

      for(intq=0;q <3;q++){

      for(inti=0;i <numPixels();i=i+3){

      setPixelColor(i+q,c);//turn every third pixel on

      }

      show();

      delay(wait);

      for(inti=0;i <numPixels();i=i+3){

      setPixelColor(i+q,0);//turn every third pixel off

      }

      }

      }

      }

      //Theatre-style crawling lights with rainbow effect

      voidtheaterChaseRainbow(uint8_twait){

      for(intj=0;j <256;j++){// cycle all 256 colors in the wheel

      for(intq=0;q <3;q++){

      for(inti=0;i <numPixels();i=i+3){

      setPixelColor(i+q,Wheel((i+j)%255));//turn every third pixel on

      }

      show();

      delay(wait);

      for(inti=0;i <numPixels();i=i+3){

      setPixelColor(i+q,0);//turn every third pixel off

      }

      }

      }

      }

      voidstartShow(inti){

      switch(i){

      case0:colorWipe(Color(0,0,0),50);// Black/off

      break;

      case1:colorWipe(Color(255,0,0),50);// Red

      break;

      case2:colorWipe(Color(0,255,0),50);// Green

      break;

      case3:colorWipe(Color(0,0,255),50);// Blue

      break;

      case4:theaterChase(Color(127,127,127),50);// White

      break;

      case5:theaterChase(Color(127,0,0),50);// Red

      break;

      case6:theaterChase(Color(0,0,127),50);// Blue

      break;

      case7:rainbow(20);

      break;

      case8:rainbowCycle(5);

      break;

      case9:theaterChaseRainbow(10);

      break;

      }

      }

      The effect is as shown in the picture/video

      https://www.bilibili.com/video/BV1wN4y157cM/


This post is from DigiKey Technology Zone

Latest reply

I watched the effect video, it's very cool [attach]651192[/attach]   Details Published on 2022-10-25 08:37
 
 

6593

Posts

0

Resources
2
 

I watched the effect video, it's very cool

This post is from DigiKey Technology Zone
 
 
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list