手头有64位和256位WS2812B的硬屏各一片,现在尝试点亮它们

WS2812主要特点
● 智能反接保护,电源反接不会损坏IC。
● IC控制电路与LED点光源公用一个电源。
● 控制电路与RGB芯片集成在一个5050封装的元器件中,构成一个完整的外控像素点。
● 内置信号整形电路,任何一个像素点收到信号后经过波形整形再输出,保证线路波形畸变不会累加。
● 内置上电复位和掉电复位电路。
● 每个像素点的三基色颜色可实现256级亮度显示,完成16777216种颜色的全真色彩显示,扫描频率不低于400Hz/s。
● 串行级联接口,能通过一根信号线完成数据的接收与解码。
● 任意两点传传输距离在不超过5米时无需增加任何电路。
● 当刷新速率30帧/秒时,级联数不小于1024点。
● 数据发送速度可达800Kbps。
● 光的颜色高度一致,性价比高。

WS2812模块电原理图

合宙CORE ESP32-C3核心板,是基于乐鑫ESP32-C3芯片进行设计的一款开发板。尺寸仅有21mm×51mm,板边采用邮票孔设计,板载 Wi-Fi/BLE天线,方便开发者在不同场景下的使用。核心板支持UART、GPIO、SPI、I2C、ADC、PWM等接口,可根据实际需要选用。

1路SPI FLASH,板载4MB,支持最高 16MB
2路UART接口,UART0~UART1,其中下载口为UART0
6 路 12 比特 ADC,最高采样率 100KSPS
1路低速SPI接口,支持主模式
1路IIC控制器
4路PWM接口
GPIO外部管脚15路,可复用
2路贴片LED指示灯
1路复位按键+1路BOOT按键
1路USB转TTL下载调试口
2.4G PCB板载天线

打开Arduino IDE——工具——管理库,搜索Adafruit NeoPixel,并安装

【花雕体验】19 合宙ESP32_C3点亮WS2812B硬屏
实验程序一:64位绿色上漂灯

/*【花雕体验】19 合宙ESP32_C3点亮WS2812B硬屏实验程序一:64位绿色上漂灯
*/#include <Adafruit_NeoPixel.h>#define PIN 9
#define MAX_LED 64int val = 0;Adafruit_NeoPixel strip = Adafruit_NeoPixel( MAX_LED, PIN, NEO_RGB + NEO_KHZ800 );void setup() {strip.setBrightness(150);strip.begin();strip.show();
}void loop() {uint8_t i, a = 0;uint32_t color = strip.Color(160, 10, 10);while (a < 64){for (i = 0; i < 64; i++){if (i == a) strip.setPixelColor(i, color);else strip.setPixelColor(i, 0);}strip.show();delay(6);a++;}
}

实验串口返回情况

实验场景图 动态图

http://bbs.eeworld.com.cn/data/attachment/forum/202207/12/114817i2mpwpmvfzf0mn7w.gif

【花雕体验】19 合宙ESP32_C3点亮WS2812B硬屏
实验程序二:一个基本的NeoPixel 灯板灯条测试程序

/*【花雕体验】19 合宙ESP32_C3点亮WS2812B硬屏实验程序二:一个基本的NeoPixel 灯板灯条测试程序
*/#include <Adafruit_NeoPixel.h>#define PIN 9
#define NUMPIXELS 64Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);void setup() {strip.setBrightness(50);strip.begin();strip.show();
}void loop() {// Fill along the length of the strip in various colors...colorWipe(strip.Color(255,   0,   0), 50); // RedcolorWipe(strip.Color(  0, 255,   0), 50); // GreencolorWipe(strip.Color(  0,   0, 255), 50); // Blue// Do a theater marquee effect in various colors...theaterChase(strip.Color(127, 127, 127), 50); // White, half brightnesstheaterChase(strip.Color(127,   0,   0), 50); // Red, half brightnesstheaterChase(strip.Color(  0,   0, 127), 50); // Blue, half brightnessrainbow(10);             // Flowing rainbow cycle along the whole striptheaterChaseRainbow(50); // Rainbow-enhanced theaterChase variant
}// Some functions of our own for creating animated effects -----------------// Fill strip pixels one after another with a color. Strip is NOT cleared
// first; anything there will be covered pixel by pixel. Pass in color
// (as a single 'packed' 32-bit value, which you can get by calling
// strip.Color(red, green, blue) as shown in the loop() function above),
// and a delay time (in milliseconds) between pixels.
void colorWipe(uint32_t color, int wait) {for (int i = 0; i < strip.numPixels(); i++) { // For each pixel in strip...strip.setPixelColor(i, color);         //  Set pixel's color (in RAM)strip.show();                          //  Update strip to matchdelay(wait);                           //  Pause for a moment}
}// Theater-marquee-style chasing lights. Pass in a color (32-bit value,
// a la strip.Color(r,g,b) as mentioned above), and a delay time (in ms)
// between frames.
void theaterChase(uint32_t color, int wait) {for (int a = 0; a < 10; a++) { // Repeat 10 times...for (int b = 0; b < 3; b++) { //  'b' counts from 0 to 2...strip.clear();         //   Set all pixels in RAM to 0 (off)// 'c' counts up from 'b' to end of strip in steps of 3...for (int c = b; c < strip.numPixels(); c += 3) {strip.setPixelColor(c, color); // Set pixel 'c' to value 'color'}strip.show(); // Update strip with new contentsdelay(wait);  // Pause for a moment}}
}// Rainbow cycle along whole strip. Pass delay time (in ms) between frames.
void rainbow(int wait) {// Hue of first pixel runs 5 complete loops through the color wheel.// Color wheel has a range of 65536 but it's OK if we roll over, so// just count from 0 to 5*65536. Adding 256 to firstPixelHue each time// means we'll make 5*65536/256 = 1280 passes through this outer loop:for (long firstPixelHue = 0; firstPixelHue < 5 * 65536; firstPixelHue += 256) {for (int i = 0; i < strip.numPixels(); i++) { // For each pixel in strip...// Offset pixel hue by an amount to make one full revolution of the// color wheel (range of 65536) along the length of the strip// (strip.numPixels() steps):int pixelHue = firstPixelHue + (i * 65536L / strip.numPixels());// strip.ColorHSV() can take 1 or 3 arguments: a hue (0 to 65535) or// optionally add saturation and value (brightness) (each 0 to 255).// Here we're using just the single-argument hue variant. The result// is passed through strip.gamma32() to provide 'truer' colors// before assigning to each pixel:strip.setPixelColor(i, strip.gamma32(strip.ColorHSV(pixelHue)));}strip.show(); // Update strip with new contentsdelay(wait);  // Pause for a moment}
}// Rainbow-enhanced theater marquee. Pass delay time (in ms) between frames.
void theaterChaseRainbow(int wait) {int firstPixelHue = 0;     // First pixel starts at red (hue 0)for (int a = 0; a < 30; a++) { // Repeat 30 times...for (int b = 0; b < 3; b++) { //  'b' counts from 0 to 2...strip.clear();         //   Set all pixels in RAM to 0 (off)// 'c' counts up from 'b' to end of strip in increments of 3...for (int c = b; c < strip.numPixels(); c += 3) {// hue of pixel 'c' is offset by an amount to make one full// revolution of the color wheel (range 65536) along the length// of the strip (strip.numPixels() steps):int      hue   = firstPixelHue + c * 65536L / strip.numPixels();uint32_t color = strip.gamma32(strip.ColorHSV(hue)); // hue -> RGBstrip.setPixelColor(c, color); // Set pixel 'c' to value 'color'}strip.show();                // Update strip with new contentsdelay(wait);                 // Pause for a momentfirstPixelHue += 65536 / 90; // One cycle of color wheel over 90 frames}}
}

实验场景图 动态图

http://bbs.eeworld.com.cn/data/attachment/forum/202207/12/135553bdzang6a7tqdxx06.gif

实验场景图 动态图

http://bbs.eeworld.com.cn/data/attachment/forum/202207/12/135832qniizw6t6knedk6k.gif

实验场景图 动态图

http://bbs.eeworld.com.cn/data/attachment/forum/202207/12/140044pk77mj7777q8g746.gif

【花雕体验】19 合宙ESP32_C3点亮WS2812B硬屏
实验程序三:256位显示 RGBW 的 WHITE 通道的测试使用

/*【花雕体验】19 合宙ESP32_C3点亮WS2812B硬屏实验程序三:256位显示 RGBW 的 WHITE 通道的测试使用
*/#include <Adafruit_NeoPixel.h>#define LED_PIN 9
#define LED_COUNT 256Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRBW + NEO_KHZ800);void setup() {strip.setBrightness(30);strip.begin();strip.show();
}void loop() {// Fill along the length of the strip in various colors...colorWipe(strip.Color(255,   0,   0)     , 50); // RedcolorWipe(strip.Color(  0, 255,   0)     , 50); // GreencolorWipe(strip.Color(  0,   0, 255)     , 50); // BluecolorWipe(strip.Color(  0,   0,   0, 255), 50); // True white (not RGB white)whiteOverRainbow(75, 5);pulseWhite(5);rainbowFade2White(3, 3, 1);
}// Fill strip pixels one after another with a color. Strip is NOT cleared
// first; anything there will be covered pixel by pixel. Pass in color
// (as a single 'packed' 32-bit value, which you can get by calling
// strip.Color(red, green, blue) as shown in the loop() function above),
// and a delay time (in milliseconds) between pixels.
void colorWipe(uint32_t color, int wait) {for (int i = 0; i < strip.numPixels(); i++) { // For each pixel in strip...strip.setPixelColor(i, color);         //  Set pixel's color (in RAM)strip.show();                          //  Update strip to matchdelay(wait);                           //  Pause for a moment}
}void whiteOverRainbow(int whiteSpeed, int whiteLength) {if (whiteLength >= strip.numPixels()) whiteLength = strip.numPixels() - 1;int      head          = whiteLength - 1;int      tail          = 0;int      loops         = 3;int      loopNum       = 0;uint32_t lastTime      = millis();uint32_t firstPixelHue = 0;for (;;) { // Repeat forever (or until a 'break' or 'return')for (int i = 0; i < strip.numPixels(); i++) { // For each pixel in strip...if (((i >= tail) && (i <= head)) ||     //  If between head & tail...((tail > head) && ((i >= tail) || (i <= head)))) {strip.setPixelColor(i, strip.Color(0, 0, 0, 255)); // Set white} else {                                             // else set rainbowint pixelHue = firstPixelHue + (i * 65536L / strip.numPixels());strip.setPixelColor(i, strip.gamma32(strip.ColorHSV(pixelHue)));}}strip.show(); // Update strip with new contents// There's no delay here, it just runs full-tilt until the timer and// counter combination below runs out.firstPixelHue += 40; // Advance just a little along the color wheelif ((millis() - lastTime) > whiteSpeed) { // Time to update head/tail?if (++head >= strip.numPixels()) {     // Advance head, wrap aroundhead = 0;if (++loopNum >= loops) return;}if (++tail >= strip.numPixels()) {     // Advance tail, wrap aroundtail = 0;}lastTime = millis();                   // Save time of last movement}}
}void pulseWhite(uint8_t wait) {for (int j = 0; j < 256; j++) { // Ramp up from 0 to 255// Fill entire strip with white at gamma-corrected brightness level 'j':strip.fill(strip.Color(0, 0, 0, strip.gamma8(j)));strip.show();delay(wait);}for (int j = 255; j >= 0; j--) { // Ramp down from 255 to 0strip.fill(strip.Color(0, 0, 0, strip.gamma8(j)));strip.show();delay(wait);}
}void rainbowFade2White(int wait, int rainbowLoops, int whiteLoops) {int fadeVal = 0, fadeMax = 100;// Hue of first pixel runs 'rainbowLoops' complete loops through the color// wheel. Color wheel has a range of 65536 but it's OK if we roll over, so// just count from 0 to rainbowLoops*65536, using steps of 256 so we// advance around the wheel at a decent clip.for (uint32_t firstPixelHue = 0; firstPixelHue < rainbowLoops * 65536;firstPixelHue += 256) {for (int i = 0; i < strip.numPixels(); i++) { // For each pixel in strip...// Offset pixel hue by an amount to make one full revolution of the// color wheel (range of 65536) along the length of the strip// (strip.numPixels() steps):uint32_t pixelHue = firstPixelHue + (i * 65536L / strip.numPixels());// strip.ColorHSV() can take 1 or 3 arguments: a hue (0 to 65535) or// optionally add saturation and value (brightness) (each 0 to 255).// Here we're using just the three-argument variant, though the// second value (saturation) is a constant 255.strip.setPixelColor(i, strip.gamma32(strip.ColorHSV(pixelHue, 255,255 * fadeVal / fadeMax)));}strip.show();delay(wait);if (firstPixelHue < 65536) {                             // First loop,if (fadeVal < fadeMax) fadeVal++;                      // fade in} else if (firstPixelHue >= ((rainbowLoops - 1) * 65536)) { // Last loop,if (fadeVal > 0) fadeVal--;                            // fade out} else {fadeVal = fadeMax; // Interim loop, make sure fade is at max}}for (int k = 0; k < whiteLoops; k++) {for (int j = 0; j < 256; j++) { // Ramp up 0 to 255// Fill entire strip with white at gamma-corrected brightness level 'j':strip.fill(strip.Color(0, 0, 0, strip.gamma8(j)));strip.show();}delay(100); // Pause 1 secondfor (int j = 255; j >= 0; j--) { // Ramp down 255 to 0strip.fill(strip.Color(0, 0, 0, strip.gamma8(j)));strip.show();}}delay(50); // Pause 1/2 second
}

实验场景图

实验场景图 动态图

http://bbs.eeworld.com.cn/data/attachment/forum/202207/12/144311ivznk4v2can2lsal.gif

【花雕体验】19 合宙ESP32_C3点亮WS2812B硬屏
实验程序四:256位使用FastLED库的八种快速调色板

/*【花雕体验】19 合宙ESP32_C3点亮WS2812B硬屏实验程序四:256位使用FastLED库的八种快速调色板
*/#include <FastLED.h>#define LED_PIN     9
#define NUM_LEDS    256
#define BRIGHTNESS  20
#define LED_TYPE    WS2811
#define COLOR_ORDER GRB
CRGB leds[NUM_LEDS];#define UPDATES_PER_SECOND 100CRGBPalette16 currentPalette;
TBlendType    currentBlending;extern CRGBPalette16 myRedWhiteBluePalette;
extern const TProgmemPalette16 myRedWhiteBluePalette_p PROGMEM;void setup() {delay( 3000 ); // power-up safety delayFastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );FastLED.setBrightness(  BRIGHTNESS );currentPalette = RainbowColors_p;currentBlending = LINEARBLEND;
}void loop() {ChangePalettePeriodically();static uint8_t startIndex = 0;startIndex = startIndex + 1; /* motion speed */FillLEDsFromPaletteColors( startIndex);FastLED.show();FastLED.delay(1000 / UPDATES_PER_SECOND);
}void FillLEDsFromPaletteColors( uint8_t colorIndex) {uint8_t brightness = 255;for ( int i = 0; i < NUM_LEDS; ++i) {leds[i] = ColorFromPalette( currentPalette, colorIndex, brightness, currentBlending);colorIndex += 3;}
}void ChangePalettePeriodically() {uint8_t secondHand = (millis() / 1000) % 60;static uint8_t lastSecond = 99;if ( lastSecond != secondHand) {lastSecond = secondHand;if ( secondHand ==  0)  {currentPalette = RainbowColors_p;currentBlending = LINEARBLEND;}if ( secondHand == 10)  {currentPalette = RainbowStripeColors_p;currentBlending = NOBLEND;}if ( secondHand == 15)  {currentPalette = RainbowStripeColors_p;currentBlending = LINEARBLEND;}if ( secondHand == 20)  {SetupPurpleAndGreenPalette();currentBlending = LINEARBLEND;}if ( secondHand == 25)  {SetupTotallyRandomPalette();currentBlending = LINEARBLEND;}if ( secondHand == 30)  {SetupBlackAndWhiteStripedPalette();currentBlending = NOBLEND;}if ( secondHand == 35)  {SetupBlackAndWhiteStripedPalette();currentBlending = LINEARBLEND;}if ( secondHand == 40)  {currentPalette = CloudColors_p;currentBlending = LINEARBLEND;}if ( secondHand == 45)  {currentPalette = PartyColors_p;currentBlending = LINEARBLEND;}if ( secondHand == 50)  {currentPalette = myRedWhiteBluePalette_p;currentBlending = NOBLEND;}if ( secondHand == 55)  {currentPalette = myRedWhiteBluePalette_p;currentBlending = LINEARBLEND;}}
}// This function fills the palette with totally random colors.
void SetupTotallyRandomPalette() {for ( int i = 0; i < 16; ++i) {currentPalette[i] = CHSV( random8(), 255, random8());}
}void SetupBlackAndWhiteStripedPalette() {// 'black out' all 16 palette entries...fill_solid( currentPalette, 16, CRGB::Black);// and set every fourth one to white.currentPalette[0] = CRGB::White;currentPalette[4] = CRGB::White;currentPalette[8] = CRGB::White;currentPalette[12] = CRGB::White;
}// This function sets up a palette of purple and green stripes.
void SetupPurpleAndGreenPalette() {CRGB purple = CHSV( HUE_PURPLE, 255, 255);CRGB green  = CHSV( HUE_GREEN, 255, 255);CRGB black  = CRGB::Black;currentPalette = CRGBPalette16(green,  green,  black,  black,purple, purple, black,  black,green,  green,  black,  black,purple, purple, black,  black );
}const TProgmemPalette16 myRedWhiteBluePalette_p PROGMEM =
{CRGB::Red,CRGB::Gray, // 'white' is too bright compared to red and blueCRGB::Blue,CRGB::Black,CRGB::Red,CRGB::Gray,CRGB::Blue,CRGB::Black,CRGB::Red,CRGB::Red,CRGB::Gray,CRGB::Gray,CRGB::Blue,CRGB::Blue,CRGB::Black,CRGB::Black
};

实验场景图

实验场景图 动态图

http://bbs.eeworld.com.cn/data/attachment/forum/202207/12/150437zbr1czzaawsalr1a.gif

【花雕体验】19 合宙ESP32_C3点亮WS2812B硬屏
实验程序五:TwinkleFOX:淡入淡出的闪烁“节日灯“

/*【花雕体验】19 合宙ESP32_C3点亮WS2812B硬屏实验程序五:TwinkleFOX:淡入淡出的闪烁“节日灯“
*/#include "FastLED.h"#define NUM_LEDS      256
#define LED_TYPE   WS2811
#define COLOR_ORDER   GRB
#define DATA_PIN        9
//#define CLK_PIN       4
#define VOLTS          12
#define MAX_MA       4000//  TwinkleFOX: Twinkling 'holiday' lights that fade in and out.
//  Colors are chosen from a palette; a few palettes are provided.
//
//  This December 2015 implementation improves on the December 2014 version
//  in several ways:
//  - smoother fading, compatible with any colors and any palettes
//  - easier control of twinkle speed and twinkle density
//  - supports an optional 'background color'
//  - takes even less RAM: zero RAM overhead per pixel
//  - illustrates a couple of interesting techniques (uh oh...)
//
//  The idea behind this (new) implementation is that there's one
//  basic, repeating pattern that each pixel follows like a waveform:
//  The brightness rises from 0..255 and then falls back down to 0.
//  The brightness at any given point in time can be determined as
//  as a function of time, for example:
//    brightness = sine( time ); // a sine wave of brightness over time
//
//  So the way this implementation works is that every pixel follows
//  the exact same wave function over time.  In this particular case,
//  I chose a sawtooth triangle wave (triwave8) rather than a sine wave,
//  but the idea is the same: brightness = triwave8( time ).
//
//  Of course, if all the pixels used the exact same wave form, and
//  if they all used the exact same 'clock' for their 'time base', all
//  the pixels would brighten and dim at once -- which does not look
//  like twinkling at all.
//
//  So to achieve random-looking twinkling, each pixel is given a
//  slightly different 'clock' signal.  Some of the clocks run faster,
//  some run slower, and each 'clock' also has a random offset from zero.
//  The net result is that the 'clocks' for all the pixels are always out
//  of sync from each other, producing a nice random distribution
//  of twinkles.
//
//  The 'clock speed adjustment' and 'time offset' for each pixel
//  are generated randomly.  One (normal) approach to implementing that
//  would be to randomly generate the clock parameters for each pixel
//  at startup, and store them in some arrays.  However, that consumes
//  a great deal of precious RAM, and it turns out to be totally
//  unnessary!  If the random number generate is 'seeded' with the
//  same starting value every time, it will generate the same sequence
//  of values every time.  So the clock adjustment parameters for each
//  pixel are 'stored' in a pseudo-random number generator!  The PRNG
//  is reset, and then the first numbers out of it are the clock
//  adjustment parameters for the first pixel, the second numbers out
//  of it are the parameters for the second pixel, and so on.
//  In this way, we can 'store' a stable sequence of thousands of
//  random clock adjustment parameters in literally two bytes of RAM.
//
//  There's a little bit of fixed-point math involved in applying the
//  clock speed adjustments, which are expressed in eighths.  Each pixel's
//  clock speed ranges from 8/8ths of the system clock (i.e. 1x) to
//  23/8ths of the system clock (i.e. nearly 3x).
//
//  On a basic Arduino Uno or Leonardo, this code can twinkle 300+ pixels
//  smoothly at over 50 updates per seond.
//
//  -Mark Kriegsman, December 2015CRGBArray<NUM_LEDS> leds;// Overall twinkle speed.
// 0 (VERY slow) to 8 (VERY fast).
// 4, 5, and 6 are recommended, default is 4.
#define TWINKLE_SPEED 8// Overall twinkle density.
// 0 (NONE lit) to 8 (ALL lit at once).
// Default is 5.
#define TWINKLE_DENSITY 5// How often to change color palettes.
#define SECONDS_PER_PALETTE  10
// Also: toward the bottom of the file is an array
// called "ActivePaletteList" which controls which color
// palettes are used; you can add or remove color palettes
// from there freely.// Background color for 'unlit' pixels
// Can be set to CRGB::Black if desired.
CRGB gBackgroundColor = CRGB::Black;
// Example of dim incandescent fairy light background color
// CRGB gBackgroundColor = CRGB(CRGB::FairyLight).nscale8_video(16);// If AUTO_SELECT_BACKGROUND_COLOR is set to 1,
// then for any palette where the first two entries
// are the same, a dimmed version of that color will
// automatically be used as the background color.
#define AUTO_SELECT_BACKGROUND_COLOR 0// If COOL_LIKE_INCANDESCENT is set to 1, colors will
// fade out slighted 'reddened', similar to how
// incandescent bulbs change color as they get dim down.
#define COOL_LIKE_INCANDESCENT 1CRGBPalette16 gCurrentPalette;
CRGBPalette16 gTargetPalette;void setup() {delay( 2000 ); //safety startup delayFastLED.setMaxPowerInVoltsAndMilliamps( VOLTS, MAX_MA);FastLED.addLeds<LED_TYPE, DATA_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);FastLED.setBrightness(22);chooseNextColorPalette(gTargetPalette);
}void loop(){EVERY_N_SECONDS( SECONDS_PER_PALETTE ) {chooseNextColorPalette( gTargetPalette );}EVERY_N_MILLISECONDS( 10 ) {nblendPaletteTowardPalette( gCurrentPalette, gTargetPalette, 12);}drawTwinkles( leds);FastLED.show();
}//  This function loops over each pixel, calculates the
//  adjusted 'clock' that this pixel should use, and calls
//  "CalculateOneTwinkle" on each pixel.  It then displays
//  either the twinkle color of the background color,
//  whichever is brighter.
void drawTwinkles( CRGBSet& L)
{// "PRNG16" is the pseudorandom number generator// It MUST be reset to the same starting value each time// this function is called, so that the sequence of 'random'// numbers that it generates is (paradoxically) stable.uint16_t PRNG16 = 11337;uint32_t clock32 = millis();// Set up the background color, "bg".// if AUTO_SELECT_BACKGROUND_COLOR == 1, and the first two colors of// the current palette are identical, then a deeply faded version of// that color is used for the background colorCRGB bg;if ( (AUTO_SELECT_BACKGROUND_COLOR == 1) &&(gCurrentPalette[0] == gCurrentPalette[1] )) {bg = gCurrentPalette[0];uint8_t bglight = bg.getAverageLight();if ( bglight > 64) {bg.nscale8_video( 16); // very bright, so scale to 1/16th} else if ( bglight > 16) {bg.nscale8_video( 64); // not that bright, so scale to 1/4th} else {bg.nscale8_video( 86); // dim, scale to 1/3rd.}} else {bg = gBackgroundColor; // just use the explicitly defined background color}uint8_t backgroundBrightness = bg.getAverageLight();for ( CRGB& pixel : L) {PRNG16 = (uint16_t)(PRNG16 * 2053) + 1384; // next 'random' numberuint16_t myclockoffset16 = PRNG16; // use that number as clock offsetPRNG16 = (uint16_t)(PRNG16 * 2053) + 1384; // next 'random' number// use that number as clock speed adjustment factor (in 8ths, from 8/8ths to 23/8ths)uint8_t myspeedmultiplierQ5_3 =  ((((PRNG16 & 0xFF) >> 4) + (PRNG16 & 0x0F)) & 0x0F) + 0x08;uint32_t myclock30 = (uint32_t)((clock32 * myspeedmultiplierQ5_3) >> 3) + myclockoffset16;uint8_t  myunique8 = PRNG16 >> 8; // get 'salt' value for this pixel// We now have the adjusted 'clock' for this pixel, now we call// the function that computes what color the pixel should be based// on the "brightness = f( time )" idea.CRGB c = computeOneTwinkle( myclock30, myunique8);uint8_t cbright = c.getAverageLight();int16_t deltabright = cbright - backgroundBrightness;if ( deltabright >= 32 || (!bg)) {// If the new pixel is significantly brighter than the background color,// use the new color.pixel = c;} else if ( deltabright > 0 ) {// If the new pixel is just slightly brighter than the background color,// mix a blend of the new color and the background colorpixel = blend( bg, c, deltabright * 8);} else {// if the new pixel is not at all brighter than the background color,// just use the background color.pixel = bg;}}
}//  This function takes a time in pseudo-milliseconds,
//  figures out brightness = f( time ), and also hue = f( time )
//  The 'low digits' of the millisecond time are used as
//  input to the brightness wave function.
//  The 'high digits' are used to select a color, so that the color
//  does not change over the course of the fade-in, fade-out
//  of one cycle of the brightness wave function.
//  The 'high digits' are also used to determine whether this pixel
//  should light at all during this cycle, based on the TWINKLE_DENSITY.
CRGB computeOneTwinkle( uint32_t ms, uint8_t salt)
{uint16_t ticks = ms >> (8 - TWINKLE_SPEED);uint8_t fastcycle8 = ticks;uint16_t slowcycle16 = (ticks >> 8) + salt;slowcycle16 += sin8( slowcycle16);slowcycle16 =  (slowcycle16 * 2053) + 1384;uint8_t slowcycle8 = (slowcycle16 & 0xFF) + (slowcycle16 >> 8);uint8_t bright = 0;if ( ((slowcycle8 & 0x0E) / 2) < TWINKLE_DENSITY) {bright = attackDecayWave8( fastcycle8);}uint8_t hue = slowcycle8 - salt;CRGB c;if ( bright > 0) {c = ColorFromPalette( gCurrentPalette, hue, bright, NOBLEND);if ( COOL_LIKE_INCANDESCENT == 1 ) {coolLikeIncandescent( c, fastcycle8);}} else {c = CRGB::Black;}return c;
}// This function is like 'triwave8', which produces a
// symmetrical up-and-down triangle sawtooth waveform, except that this
// function produces a triangle wave with a faster attack and a slower decay:
//
//     / \
//    /     \
//   /         \
//  /             \
//uint8_t attackDecayWave8( uint8_t i)
{if ( i < 86) {return i * 3;} else {i -= 86;return 255 - (i + (i / 2));}
}// This function takes a pixel, and if its in the 'fading down'
// part of the cycle, it adjusts the color a little bit like the
// way that incandescent bulbs fade toward 'red' as they dim.
void coolLikeIncandescent( CRGB& c, uint8_t phase)
{if ( phase < 128) return;uint8_t cooling = (phase - 128) >> 4;c.g = qsub8( c.g, cooling);c.b = qsub8( c.b, cooling * 2);
}// A mostly red palette with green accents and white trim.
// "CRGB::Gray" is used as white to keep the brightness more uniform.
const TProgmemRGBPalette16 RedGreenWhite_p FL_PROGMEM =
{ CRGB::Red, CRGB::Red, CRGB::Red, CRGB::Red,CRGB::Red, CRGB::Red, CRGB::Red, CRGB::Red,CRGB::Red, CRGB::Red, CRGB::Gray, CRGB::Gray,CRGB::Green, CRGB::Green, CRGB::Green, CRGB::Green
};// A mostly (dark) green palette with red berries.
#define Holly_Green 0x00580c
#define Holly_Red   0xB00402
const TProgmemRGBPalette16 Holly_p FL_PROGMEM =
{ Holly_Green, Holly_Green, Holly_Green, Holly_Green,Holly_Green, Holly_Green, Holly_Green, Holly_Green,Holly_Green, Holly_Green, Holly_Green, Holly_Green,Holly_Green, Holly_Green, Holly_Green, Holly_Red
};// A red and white striped palette
// "CRGB::Gray" is used as white to keep the brightness more uniform.
const TProgmemRGBPalette16 RedWhite_p FL_PROGMEM =
{ CRGB::Red,  CRGB::Red,  CRGB::Red,  CRGB::Red,CRGB::Gray, CRGB::Gray, CRGB::Gray, CRGB::Gray,CRGB::Red,  CRGB::Red,  CRGB::Red,  CRGB::Red,CRGB::Gray, CRGB::Gray, CRGB::Gray, CRGB::Gray
};// A mostly blue palette with white accents.
// "CRGB::Gray" is used as white to keep the brightness more uniform.
const TProgmemRGBPalette16 BlueWhite_p FL_PROGMEM =
{ CRGB::Blue, CRGB::Blue, CRGB::Blue, CRGB::Blue,CRGB::Blue, CRGB::Blue, CRGB::Blue, CRGB::Blue,CRGB::Blue, CRGB::Blue, CRGB::Blue, CRGB::Blue,CRGB::Blue, CRGB::Gray, CRGB::Gray, CRGB::Gray
};// A pure "fairy light" palette with some brightness variations
#define HALFFAIRY ((CRGB::FairyLight & 0xFEFEFE) / 2)
#define QUARTERFAIRY ((CRGB::FairyLight & 0xFCFCFC) / 4)
const TProgmemRGBPalette16 FairyLight_p FL_PROGMEM =
{ CRGB::FairyLight, CRGB::FairyLight, CRGB::FairyLight, CRGB::FairyLight,HALFFAIRY,        HALFFAIRY,        CRGB::FairyLight, CRGB::FairyLight,QUARTERFAIRY,     QUARTERFAIRY,     CRGB::FairyLight, CRGB::FairyLight,CRGB::FairyLight, CRGB::FairyLight, CRGB::FairyLight, CRGB::FairyLight
};// A palette of soft snowflakes with the occasional bright one
const TProgmemRGBPalette16 Snow_p FL_PROGMEM =
{ 0x304048, 0x304048, 0x304048, 0x304048,0x304048, 0x304048, 0x304048, 0x304048,0x304048, 0x304048, 0x304048, 0x304048,0x304048, 0x304048, 0x304048, 0xE0F0FF
};// A palette reminiscent of large 'old-school' C9-size tree lights
// in the five classic colors: red, orange, green, blue, and white.
#define C9_Red    0xB80400
#define C9_Orange 0x902C02
#define C9_Green  0x046002
#define C9_Blue   0x070758
#define C9_White  0x606820
const TProgmemRGBPalette16 RetroC9_p FL_PROGMEM =
{ C9_Red,    C9_Orange, C9_Red,    C9_Orange,C9_Orange, C9_Red,    C9_Orange, C9_Red,C9_Green,  C9_Green,  C9_Green,  C9_Green,C9_Blue,   C9_Blue,   C9_Blue,C9_White
};// A cold, icy pale blue palette
#define Ice_Blue1 0x0C1040
#define Ice_Blue2 0x182080
#define Ice_Blue3 0x5080C0
const TProgmemRGBPalette16 Ice_p FL_PROGMEM =
{Ice_Blue1, Ice_Blue1, Ice_Blue1, Ice_Blue1,Ice_Blue1, Ice_Blue1, Ice_Blue1, Ice_Blue1,Ice_Blue1, Ice_Blue1, Ice_Blue1, Ice_Blue1,Ice_Blue2, Ice_Blue2, Ice_Blue2, Ice_Blue3
};// Add or remove palette names from this list to control which color
// palettes are used, and in what order.
const TProgmemRGBPalette16* ActivePaletteList[] = {&RetroC9_p,&BlueWhite_p,&RainbowColors_p,&FairyLight_p,&RedGreenWhite_p,&PartyColors_p,&RedWhite_p,&Snow_p,&Holly_p,&Ice_p
};// Advance to the next color palette in the list (above).
void chooseNextColorPalette( CRGBPalette16& pal)
{const uint8_t numberOfPalettes = sizeof(ActivePaletteList) / sizeof(ActivePaletteList[0]);static uint8_t whichPalette = -1;whichPalette = addmod8( whichPalette, 1, numberOfPalettes);pal = *(ActivePaletteList[whichPalette]);
}

实验场景图 动态图

http://bbs.eeworld.com.cn/data/attachment/forum/202207/12/152608ad8npicefu8xe5qn.gif

【花雕体验】19 合宙ESP32_C3点亮WS2812B硬屏
实验程序六:FastLED“100行代码”演示卷轴动画效果

/*【花雕体验】19 合宙ESP32_C3点亮WS2812B硬屏实验程序六:FastLED“100行代码”演示卷轴动画效果
*/#include <FastLED.h>FASTLED_USING_NAMESPACE// FastLED "100-lines-of-code" demo reel, showing just a few
// of the kinds of animation patterns you can quickly and easily
// compose using FastLED.
//
// This example also shows one easy way to define multiple
// animations patterns and have them automatically rotate.
//
// -Mark Kriegsman, December 2014#define DATA_PIN    9
//#define CLK_PIN   4
#define LED_TYPE    WS2811
#define COLOR_ORDER GRB
#define NUM_LEDS    256
CRGB leds[NUM_LEDS];#define BRIGHTNESS          22
#define FRAMES_PER_SECOND  120void setup() {delay(1000); // 3 second delay for recovery// tell FastLED about the LED strip configurationFastLED.addLeds<LED_TYPE, DATA_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);//FastLED.addLeds<LED_TYPE,DATA_PIN,CLK_PIN,COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);// set master brightness controlFastLED.setBrightness(BRIGHTNESS);
}// List of patterns to cycle through.  Each is defined as a separate function below.
typedef void (*SimplePatternList[])();
SimplePatternList gPatterns = { rainbow, rainbowWithGlitter, confetti, sinelon, juggle, bpm };uint8_t gCurrentPatternNumber = 0; // Index number of which pattern is current
uint8_t gHue = 0; // rotating "base color" used by many of the patternsvoid loop()
{// Call the current pattern function once, updating the 'leds' arraygPatterns[gCurrentPatternNumber]();// send the 'leds' array out to the actual LED stripFastLED.show();// insert a delay to keep the framerate modestFastLED.delay(1000 / FRAMES_PER_SECOND);// do some periodic updatesEVERY_N_MILLISECONDS( 20 ) {gHue++;  // slowly cycle the "base color" through the rainbow}EVERY_N_SECONDS( 10 ) {nextPattern();  // change patterns periodically}
}#define ARRAY_SIZE(A) (sizeof(A) / sizeof((A)[0]))void nextPattern()
{// add one to the current pattern number, and wrap around at the endgCurrentPatternNumber = (gCurrentPatternNumber + 1) % ARRAY_SIZE( gPatterns);
}void rainbow()
{// FastLED's built-in rainbow generatorfill_rainbow( leds, NUM_LEDS, gHue, 7);
}void rainbowWithGlitter()
{// built-in FastLED rainbow, plus some random sparkly glitterrainbow();addGlitter(80);
}void addGlitter( fract8 chanceOfGlitter)
{if ( random8() < chanceOfGlitter) {leds[ random16(NUM_LEDS) ] += CRGB::White;}
}void confetti()
{// random colored speckles that blink in and fade smoothlyfadeToBlackBy( leds, NUM_LEDS, 10);int pos = random16(NUM_LEDS);leds[pos] += CHSV( gHue + random8(64), 200, 255);
}void sinelon()
{// a colored dot sweeping back and forth, with fading trailsfadeToBlackBy( leds, NUM_LEDS, 20);int pos = beatsin16( 13, 0, NUM_LEDS - 1 );leds[pos] += CHSV( gHue, 255, 192);
}void bpm()
{// colored stripes pulsing at a defined Beats-Per-Minute (BPM)uint8_t BeatsPerMinute = 62;CRGBPalette16 palette = PartyColors_p;uint8_t beat = beatsin8( BeatsPerMinute, 64, 255);for ( int i = 0; i < NUM_LEDS; i++) { //9948leds[i] = ColorFromPalette(palette, gHue + (i * 2), beat - gHue + (i * 10));}
}void juggle() {// eight colored dots, weaving in and out of sync with each otherfadeToBlackBy( leds, NUM_LEDS, 20);uint8_t dothue = 0;for ( int i = 0; i < 8; i++) {leds[beatsin16( i + 7, 0, NUM_LEDS - 1 )] |= CHSV(dothue, 200, 255);dothue += 32;}
}

实验场景图 动态图

https://img.mydigit.cn/forum/202207/12/161144sssbhkh4ib4vqv9q.gif

实验的视频记录

https://v.youku.com/v_show/id_XNTg4NTE1NDE4OA==.html?spm=a2hcb.playlsit.page.1

【花雕体验】19 合宙ESP32_C3点亮WS2812B硬屏相关推荐

  1. 基于Lua框架下的合宙ESP32C3+1.5‘’Eink墨水屏天气时钟+OLED开源项目分享

    基于Lua框架下的合宙ESP32C3+1.5''Eink墨水屏天气时钟+OLED项目分享

  2. 基于Lua框架下的合宙ESP32C3+1.54‘’Eink墨水屏天气时钟项目

    基于Lua框架下的合宙ESP32C3+1.5''Eink墨水屏天气时钟项目 效果展示

  3. 【花雕体验】18 行空板点亮WS2812B的256位LED硬屏

    手头有二块WS2812B硬屏板子 WS2812B主要特点 智能反接保护,电源反接不会损坏IC. IC控制电路与LED点光源公用一个电源. 控制电路与RGB芯片集成在一个5050封装的元器件中,构成一个 ...

  4. 【花雕动手做】有趣好玩的音乐可视化系列项目(29)--16X16硬屏灯

    偶然心血来潮,想要做一个音乐可视化的系列专题.这个专题的难度有点高,涉及面也比较广泛,相关的FFT和FHT等算法也相当复杂,不过还是打算从最简单的开始,实际动手做做试验,耐心尝试一下各种方案,逐步积累 ...

  5. 0.1.3 合宙CORE-ESP32-C3开发板用arduino点亮ST7735 1.8寸TFT屏【已更新失效链接2022.07.10】

    9.9的ESP32开发板想用arduino开发,无奈都是用luatos玩,于是折腾了下 目的 用arduino驱动合宙ESP32-C3开发板点亮S7735TFT屏 材料 CORE-ESP32-C3开发 ...

  6. 合宙AIR32F103CBT6入门第一步——点亮LED灯

    一.准备工作 1.材料 AIR32F103CBT6一块 ST linkv2一块 杜邦线若干 2.电脑安装 STM32 CubeMx123 [STM32]STM32 CubeMx使用教程一--安装教程_ ...

  7. X、合宙Air模块Luat开发:全网首发,通过iic直接驱动OLED,720Sl开始有显时代

    目录 点击这里查看所有博文   本系列博客,理论上适用于合宙的Air202.Air268.Air720x.Air720S以及最近发布的Air720U(我还没拿到样机,应该也能支持).   先不管支不支 ...

  8. 【花雕体验】12 搭建ESP32C3之Arduino开发环境

    1.连接 ESP32-C3 和 PC,安装驱动(CH343) (1)WCH官网下载驱动 https://www.wch.cn/downloads/CH343SER_EXE.html (2)运行安装 ( ...

  9. 合宙air105上手记录

    官方介绍:新品上市 | 更大,更强--Air105芯片&开发板重磅来袭 - 知乎 (zhihu.com) 资料:Air105 资料汇总(软硬件资料,固件下载,技术支持) (openluat.c ...

  10. 合宙-icool 开发板使用手册

    概述:iCool(idea cool)手机是基于合宙Air722UG模块,移植LittleVGL,用lua脚本语言开发的一款5寸触摸屏手机产品. 目录 1.总体介绍 2.准备工作 3.功能介绍 3.1 ...

最新文章

  1. mysql优化Analyze Table
  2. http://wenku.baidu.com/view/26afdb8371fe910ef12df8ccRevit采用DWG和FBX两种格式导入3D max方法的总结...
  3. PHP和JS三元运算顺序相反
  4. WCF IE 能够正常访问,chrome 和firefox不能正常访问
  5. /UI5/IF_UI5_REP_PERSISTENCE - why I cannot deploy app to GM6
  6. Prism for WPF 搭建一个简单的模块化开发框架
  7. 机器学习算法中的准确率、精确率、召回率和F值
  8. redis修改端口号后还是占用6379_Redis分布式缓存分布式集群搭建
  9. 手把手教你训练一个神经网络,打爆21点!
  10. 直接拿来用,10个PHP代码片段
  11. windows抓wifi包 Microsoft Network Monitor
  12. 电源技术中的onsemi ESD5B5.0ST1G,ESD9B3.3ST5G,ESD9B5.0ST5G,SZESD9B5.0ST5G,ESD静电保护管 TVS管 电容值低,反应速度快的解决方案
  13. adobe air for ubuntu + markman 安装?
  14. Linux fs清理文件,linux – 在fs崩溃并运行fsck之后,一些文件被恢复但是找不到丢失的文件?...
  15. 淮阴工学院C语言考试题库,淮阴工学院C语言题库练习题1.ppt
  16. CC00015.kylin——|HadoopOLAP_Kylin.V15|——|Kylin.v15|Cube优化|Cuboid剪枝优化|
  17. java实验三_java实验三实验报告.docx
  18. 【927. 三等分】
  19. Android自动获取短信验证码
  20. Python遥感图像处理应用篇(二十二):Python+GDAL 批量等距离裁剪影像-续

热门文章

  1. python枚举详解
  2. kotlin的by lazy
  3. pt-archiver 命令
  4. 新加坡政府将与加美两国就网络安全问题展开合作
  5. Oracle导入sas数据集,来自SAS数据集的Oracle表
  6. 11个非常炫酷的网页样式特效【附实现代码】
  7. 百度移动:静悄悄的战争
  8. Docker入门之-网络(三):容器如何与外部世界通信
  9. 《重构》笔记---坏代码的味道与处理
  10. Hypermedia 简介