采用的arduino控制,利用别人写好的模块进行控制
vs code搜索Adafruit_NeoPixel导入项目中
代码实现


#include <Adafruit_NeoPixel.h>
#ifdef __AVR__#include <avr/power.h>
#endif#define PIN 23// Parameter 1 = number of pixels in strip
// Parameter 2 = Arduino pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
//   NEO_KHZ800  800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
//   NEO_KHZ400  400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
//   NEO_GRB     Pixels are wired for GRB bitstream (most NeoPixel products)
//   NEO_RGB     Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
//   NEO_RGBW    Pixels are wired for RGBW bitstream (NeoPixel RGBW products)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(60, PIN, NEO_GRB + NEO_KHZ800);// IMPORTANT: To reduce NeoPixel burnout risk, add 1000 uF capacitor across
// pixel power leads, add 300 - 500 Ohm resistor on first pixel's data input
// and minimize distance between Arduino and first pixel.  Avoid connecting
// on a live circuit...if you must, connect GND first.// Fill the dots one after the other with a color
void colorWipe(uint32_t c, uint8_t wait) {for(uint16_t i=0; i<strip.numPixels(); i++) {strip.setPixelColor(i, c);strip.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(byte WheelPos) {WheelPos = 255 - WheelPos;if(WheelPos < 85) {return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);}if(WheelPos < 170) {WheelPos -= 85;return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);}WheelPos -= 170;return strip.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<strip.numPixels(); i++) {strip.setPixelColor(i, Wheel((i+j) & 255));}strip.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 wheelfor(i=0; i< strip.numPixels(); i++) {strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));}strip.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 chasingfor (int q=0; q < 3; q++) {for (uint16_t i=0; i < strip.numPixels(); i=i+3) {strip.setPixelColor(i+q, c);    //turn every third pixel on}strip.show();delay(wait);for (uint16_t i=0; i < strip.numPixels(); i=i+3) {strip.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 wheelfor (int q=0; q < 3; q++) {for (uint16_t i=0; i < strip.numPixels(); i=i+3) {strip.setPixelColor(i+q, Wheel( (i+j) % 255));    //turn every third pixel on}strip.show();delay(wait);for (uint16_t i=0; i < strip.numPixels(); i=i+3) {strip.setPixelColor(i+q, 0);        //turn every third pixel off}}}
}void clear(){for(uint16_t i=0; i<strip.numPixels(); i++) {strip.setPixelColor(i, 0); delay(10);}
}//流星
void meteor(uint8_t red, uint8_t green, uint8_t blue, uint8_t wait) {const uint8_t num = 8;uint8_t max_color = red;if(green > max_color)max_color = green;if(blue > max_color)max_color = blue;uint8_t instance = (max_color-200)/num;for(uint16_t i=0; i<strip.numPixels() + num; i++) {for(uint8_t j = 0; j < num; j ++){if(i - j >= 0 && i - j < strip.numPixels()){int red_after = red - (instance * j);int green_after = green - (instance * j);int blue_after = blue - (instance * j);if(j>=1){red_after -= 200;green_after -= 200;blue_after -= 200;}strip.setPixelColor(i - j, strip.Color(red_after >= 0 ? red_after : 0, green_after >= 0 ? green_after : 0, blue_after >= 0 ? blue_after : 0));}}if(i - num >= 0 && i-num < strip.numPixels())strip.setPixelColor(i-num, 0); // if(i >= 0 && i < strip.numPixels())//   strip.setPixelColor(i, strip.Color(red, green, blue));// if(i - 1 >= 0 && i-1 < strip.numPixels())//   strip.setPixelColor(i-1, strip.Color(red - 50 >= 0 ? red - 50 : 0, green - 50 >= 0 ? green - 50 : 0, blue - 50 >= 0 ? blue - 50 : 0));// if(i - 2 >= 0 && i-2 < strip.numPixels())//   strip.setPixelColor(i-2, strip.Color(red - 100 >= 0 ? red - 100 : 0, green - 100 >= 0 ? green - 100 : 0, blue - 100 >= 0 ? blue - 100 : 0));// if(i - 3 >= 0 && i-3 < strip.numPixels())//   strip.setPixelColor(i-3, strip.Color(red - 150 >= 0 ? red - 150 : 0, green - 150 >= 0 ? green - 150 : 0, blue - 150 >= 0 ? blue - 150 : 0));// if(i - 4 >= 0 && i-4 < strip.numPixels())//   strip.setPixelColor(i-4, 0); strip.show();delay(wait);}
}void meteor_overturn(uint8_t red, uint8_t green, uint8_t blue, uint8_t wait) {const uint8_t num = 8;uint8_t max_color = red;if(green > max_color)max_color = green;if(blue > max_color)max_color = blue;uint8_t instance = (max_color-200)/num;for(int i=strip.numPixels() - 1; i>=-num; i--) {for(uint8_t j = 0; j < num; j ++){if(i + j >= 0 && i + j < strip.numPixels()){int red_after = red - instance * j;int green_after = green - instance *  j;int blue_after = blue - instance *  j;if(j>=1){red_after -= 200;green_after -= 200;blue_after -= 200;}strip.setPixelColor(i + j, strip.Color(red_after >= 0 ? red_after : 0, green_after >= 0 ? green_after : 0, blue_after >= 0 ? blue_after : 0));}}if(i + num >= 0 && i+num < strip.numPixels())strip.setPixelColor(i+num, 0); // if(i == 10)//   delay(5000);// for(int i=strip.numPixels() - 1; i>=-4; i--) {//   if(i < strip.numPixels() && i >=0)//     strip.setPixelColor(i, strip.Color(red, green, blue)); //   if(i + 1 < strip.numPixels() && i+1 >=0)//     strip.setPixelColor(i+1, strip.Color(red - 50 >= 0 ? red - 50 : 0, green - 50 >= 0 ? green - 50 : 0, blue - 50 >= 0 ? blue - 50 : 0));//   if(i + 2 < strip.numPixels() && i+2 >=0)//     strip.setPixelColor(i+2, strip.Color(red - 100 >= 0 ? red - 100 : 0, green - 100 >= 0 ? green - 100 : 0, blue - 100 >= 0 ? blue - 100 : 0));//   if(i + 3 < strip.numPixels() && i+3 >=0)//     strip.setPixelColor(i+3, strip.Color(red - 150 >= 0 ? red - 150 : 0, green - 150 >= 0 ? green - 150 : 0, blue - 150 >= 0 ? blue - 150 : 0));//   if(i + 4 < strip.numPixels() && i+4 >=0)//     strip.setPixelColor(i+4, 0);strip.show();delay(wait);}
}void setup() {// This is for Trinket 5V 16MHz, you can remove these three lines if you are not using a Trinket#if defined (__AVR_ATtiny85__)if (F_CPU == 16000000) clock_prescale_set(clock_div_1);#endif// End of trinket special codestrip.begin();strip.setBrightness(100);strip.show(); // Initialize all pixels to 'off'
}void loop() {// Some example procedures showing how to display to the pixels:// colorWipe(strip.Color(255, 0, 0), 50); // Red// colorWipe(strip.Color(0, 255, 0), 50); // Green// colorWipe(strip.Color(0, 0, 255), 50); // Blue
// //colorWipe(strip.Color(0, 0, 0, 255), 50); // White RGBW
//   // Send a theater pixel chase in...// theaterChase(strip.Color(127, 127, 127), 50); // White// theaterChase(strip.Color(127, 0, 0), 200); // Red// theaterChase(strip.Color(0, 0, 127), 200); // Blue// rainbow(20);// rainbowCycle(20);// theaterChaseRainbow(100);// strip.setPixelColor(1, strip.Color(255, 255, 255)); // strip.setPixelColor(2, strip.Color(100, 100, 100)); // strip.setPixelColor(3, strip.Color(10, 10, 10)); // strip.show();clear();meteor(255, 0, 0, 20);meteor_overturn(255, 0, 0, 20);
}

灯带连接控制io和gnd,我的控制io插在了23上面
效果来回流星转动,还有其他效果没有调用,代码里面有,可以控制移动时间,总体数量,亮度等参数。

esp32 控制ws2812灯带相关推荐

  1. Arduino控制WS2812灯带(灯环)

    设计者:STCode(公众号同名) Arduino控制WS2812灯带(灯环) 1) WS2812灯 WS2812灯带 WS2812灯环 WS2812是一个集控制电路与发光电路于一体的智能外空LED光 ...

  2. 在ESP8266上控制WS2812灯带及热释电传感器原码

    请在ARDUINO IDE中自行添加Adafruit_NeoPixel库即可.测试正常. #include <Adafruit_NeoPixel.h> #ifdef __AVR__  #i ...

  3. ESP32使用外设RMT控制WS2812灯条

    目录 一.简介 二.所需材料 三.官方例程 四.使用方法 4.1 RMT初始化 4.2 WS2812初始化 4.3 点亮WS2812 五.LED颜色渐变 5.1 第一种实现方法 5.2 第二种实现方法 ...

  4. 用html5做一个简单网页_用新款ws2812灯带做一个简单的窗花

    本文转自:DF创客社区-未经许可不可转载 原文链接(附件请于原文下方下载): 用新款ws2812灯带做一个简单的窗花-创意生活论坛-DF创客社区​mc.dfrobot.com.cn 作者:屌丝王小明 ...

  5. arduino学习——WS2812灯带

    WS2812灯带程序 简介 示例程序 程序拓展(1) 程序拓展(2) 拓展程序(3)---fill_solid()函数 灯带颜色的设置 (1)CRGB RGBcolorName(rVal,gVal,b ...

  6. STM32F427库函数PWM+DMA控制ws2812b灯带

    STM32F427IIHx库函数PWM+DMA控制ws2812b灯带 一.参考资料 查看ws2812b用户手册可知: 二.代码部分 添加文件ws2812b.c,ws2812b.h 配置的F427IIH ...

  7. WS2812灯带 PWM+DMA驱动

    WS2812灯带 主控芯片GD32F303 一.ws2812灯带 1.产品特点 数据发送速度可达800Kbps 串行级联接口, 能通过一根信号线完成数据的接收与解码 任意两点传传输距离在不超过3米时无 ...

  8. 三极管实现单片机PWM控制12VRGB灯带

    通过电路分析我们发现荣事达的这款暖风机是通过PWM控制三极管快速通断实现的,相比于用驱动芯片用三极管驱动功率比较大的12V RGB灯带成本会低很多,电路设计也比较简单.   这是我们拆机的电路图: 这 ...

  9. FsatLED mixy第三方自制库 轻松玩转WS2812灯带

    续上篇  mixy第三方库 点阵屏库 LittleFS库 光敏电阻LDR库 EEPROM库 WS2812灯带库很多,如Adafruit_NeoPixel库但在mixy里样式很单一. FsatLED库 ...

最新文章

  1. CV02-FCN笔记
  2. 1020 Tree Traversals
  3. [故障解决]图文:python启动报错:api-ms-win-crt-runtime-l1-1-0.dll丢失解决
  4. InnoDB行格式(compact,redundant)对照
  5. simulated annealing
  6. windows 下搭建python虚拟环境
  7. 操作系统——存储管理:分区、分页、分段、请求式分页和虚拟内存
  8. java更新无法正常安装_Java无法安装
  9. oracle跨库插入数据,Oracle跨数据库查询并插入实现原理及代码
  10. Oracle外键约束修改行为(一)
  11. C++11 并发指南四(future 详解三 std::future std::shared_future)
  12. 类的静态成员函数和静态成员变量的使用
  13. TensorFlow by Google CNN识别猫和狗 Machine Learning Foundations: Ep #6 - Convolutional cats and dogs
  14. 小熊在线一键重装系统教程
  15. 【转】强大的在线书库
  16. 该死的强迫症,教你stm32怎么把杜邦线弄整齐
  17. “2020年嵌入式软件秋招经验和对嵌入式软件未来的一点思考”
  18. linux 设备树 usb控制器,linux 设备树中 dwc3 节点的phys参数含义
  19. 我在日本小帅哥那学习了GCN
  20. 什么是“可维护性”?

热门文章

  1. Android开发之FrameLayout
  2. C语言小游戏----俄罗斯方块
  3. 辉光翼战记 天空のユミナ 繁体免DVD破解补丁
  4. 在Docker中使用Dockerfile实现ISO文件转化为完整版Centos镜像,并搭建集群数据仓库
  5. 股票:简单看穿主力吸筹(原创)
  6. 数据挖掘学习笔记(一)
  7. 关于南方Cass的使用感受
  8. 什么是linux系统编程
  9. JAVA WEB DAY 11_ JDBC 连接池
  10. 【PdgCntEditor】利用PDF目录书签编辑软件PdgCntEditor为PDF型图书快速添加书签的方法