【雕爷学编程】Arduino动手做(86)---4*4位 WS2812 全彩模块4

news2024/9/28 23:23:02

37款传感器与执行器的提法,在网络上广泛流传,其实Arduino能够兼容的传感器模块肯定是不止这37种的。鉴于本人手头积累了一些传感器和执行器模块,依照实践出真知(一定要动手做)的理念,以学习和交流为目的,这里准备逐一动手尝试系列实验,不管成功(程序走通)与否,都会记录下来—小小的进步或是搞不掂的问题,希望能够抛砖引玉。

【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)
实验八十六:WS2812B-4*4位 RGB LED 全彩驱动16位彩灯开发板模块

在这里插入图片描述

知识点:WS2812B
是一个集控制电路与发光电路于一体的智能外控LED光源。其外型与一个5050LED灯珠相同,每个元件即为一个像素点。像素点内部包含了智能数字接口数据锁存信号整形放大驱动电路,还包含有高精度的内部振荡器和12V高压可编程定电流控制部分,有效保证了像素点光的颜色高度一致。数据协议采用单线归零码的通讯方式,像素点在上电复位以后,DIN端接受从控制器传输过来的数据,首先送过来的24bit数据被第一个像素点提取后,送到像素点内部的数据锁存器,剩余的数据经过内部整形处理电路整形放大后通过DO端口开始转发输出给下一个级联的像素点,每经过一个像素点的传输,信号减少24bit。像素点采用自动整形转发技术,使得该像素点的级联个数不受信号传送的限制,仅仅受限信号传输速度要求。
在这里插入图片描述
主要特点

● 智能反接保护,电源反接不会损坏IC。

● IC控制电路与LED点光源公用一个电源。

● 控制电路与RGB芯片集成在一个5050封装的元器件中,构成一个完整的外控像素点。

● 内置信号整形电路,任何一个像素点收到信号后经过波形整形再输出,保证线路波形畸变不会累加。

● 内置上电复位和掉电复位电路。

● 每个像素点的三基色颜色可实现256级亮度显示,完成16777216种颜色的全真色彩显示,扫描频率不低于400Hz/s。

● 串行级联接口,能通过一根信号线完成数据的接收与解码。

● 任意两点传传输距离在不超过5米时无需增加任何电路。

● 当刷新速率30帧/秒时,级联数不小于1024点。

● 数据发送速度可达800Kbps。

● 光的颜色高度一致,性价比高。

在这里插入图片描述
WS2812B-4*4位 RGB LED 全彩驱动16位彩灯开发板模块

5050高亮LED,内置控制芯片,仅需1个IO口即可控制多个LED

芯片内置整形电路,信号畸变不会累计,稳定显示

三基色256级亮度调剂,16万色真彩显示效果,扫描频率不低于400Hz/S

串行连级接口,能通过一根信号线完成数据的接收与解码

刷新速率30帧/秒时,低速连级模式连级数不小于512点

数据收发速度最高可达800Kbps

高亮LED,光色亮度一致性高

两端有l联级接口,可以直接插接
在这里插入图片描述

【Arduino】168种传感器模块系列实验(资料+代码+图形+仿真)
实验八十六: WS2812B-4*4位 RGB LED 全彩驱动16位彩灯开发板
项目十七:颜色调色板
实验接线
Module UNO
VCC —— 3.3V
GND —— GND
DI —— D6

实验开源代码

/*
  【Arduino】168种传感器模块系列实验(资料+代码+图形+仿真)
  实验八十九: WS2812B-4*4位 RGB LED 全彩驱动16位彩灯开发板
  项目十七:颜色调色板
  实验接线
  Module    UNO
  VCC —— 3.3V
  GND —— GND
  DI  ——  D6
*/

#include <FastLED.h>

#define LED_PIN     6
#define NUM_LEDS    16
#define BRIGHTNESS  33
#define LED_TYPE    WS2811
#define COLOR_ORDER GRB
CRGB leds[NUM_LEDS];

#define UPDATES_PER_SECOND 100 //定义每秒更新数

// This example shows several ways to set up and use 'palettes' of colors
// with FastLED.
//
// These compact palettes provide an easy way to re-colorize your
// animation on the fly, quickly, easily, and with low overhead.
//
// USING palettes is MUCH simpler in practice than in theory, so first just
// run this sketch, and watch the pretty lights as you then read through
// the code.  Although this sketch has eight (or more) different color schemes,
// the entire sketch compiles down to about 6.5K on AVR.
//
// FastLED provides a few pre-configured color palettes, and makes it
// extremely easy to make up your own color schemes with palettes.
//
// Some notes on the more abstract 'theory and practice' of
// FastLED compact palettes are at the bottom of this file.



CRGBPalette16 currentPalette;
TBlendType    currentBlending;

extern CRGBPalette16 myRedWhiteBluePalette;
extern const TProgmemPalette16 myRedWhiteBluePalette_p PROGMEM;


void setup() {
    delay( 3000 ); // power-up safety delay
    FastLED.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;
    }
}


// There are several different palettes of colors demonstrated here.
//
// FastLED provides several 'preset' palettes: RainbowColors_p, RainbowStripeColors_p,
// OceanColors_p, CloudColors_p, LavaColors_p, ForestColors_p, and PartyColors_p.
//
// Additionally, you can manually define your own color palettes, or you can write
// code that creates color palettes on the fly.  All are shown here.

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());
    }
}

// This function sets up a palette of black and white stripes,
// using code.  Since the palette is effectively an array of
// sixteen CRGB colors, the various fill_* functions can be used
// to set them up.
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 );
}


// This example shows how to set up a static color palette
// which is stored in PROGMEM (flash), which is almost always more
// plentiful than RAM.  A static PROGMEM palette like this
// takes up 64 bytes of flash.
const TProgmemPalette16 myRedWhiteBluePalette_p PROGMEM =
{
    CRGB::Red,
    CRGB::Gray, // 'white' is too bright compared to red and blue
    CRGB::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
};

// Additional notes on FastLED compact palettes:
//
// Normally, in computer graphics, the palette (or "color lookup table")
// has 256 entries, each containing a specific 24-bit RGB color.  You can then
// index into the color palette using a simple 8-bit (one byte) value.
// A 256-entry color palette takes up 768 bytes of RAM, which on Arduino
// is quite possibly "too many" bytes.
//
// FastLED does offer traditional 256-element palettes, for setups that
// can afford the 768-byte cost in RAM.
//
// However, FastLED also offers a compact alternative.  FastLED offers
// palettes that store 16 distinct entries, but can be accessed AS IF
// they actually have 256 entries; this is accomplished by interpolating
// between the 16 explicit entries to create fifteen intermediate palette
// entries between each pair.
//
// So for example, if you set the first two explicit entries of a compact 
// palette to Green (0,255,0) and Blue (0,0,255), and then retrieved 
// the first sixteen entries from the virtual palette (of 256), you'd get
// Green, followed by a smooth gradient from green-to-blue, and then Blue.

【Arduino】168种传感器模块系列实验(资料+代码+图形+仿真)
实验八十六: WS2812B-4*4位 RGB LED 全彩驱动16位彩灯开发板
项目十八:快速淡入淡出循环变色
实验接线
Module UNO
VCC —— 3.3V
GND —— GND
DI —— D6

实验场景图

/*
  【Arduino】168种传感器模块系列实验(资料+代码+图形+仿真)
  实验八十九: WS2812B-4*4位 RGB LED 全彩驱动16位彩灯开发板
  项目十八:快速淡入淡出循环变色
  实验接线
  Module    UNO
  VCC —— 3.3V
  GND —— GND
  DI  ——  D6
*/

#include <FastLED.h>

// How many leds in your strip?
#define NUM_LEDS 16 

// For led chips like Neopixels, which have a data line, ground, and power, you just
// need to define DATA_PIN.  For led chipsets that are SPI based (four wires - data, clock,
// ground, and power), like the LPD8806, define both DATA_PIN and CLOCK_PIN
#define DATA_PIN 6
//#define CLOCK_PIN 13

// Define the array of leds
CRGB leds[NUM_LEDS];

void setup() { 
        Serial.begin(57600);
        Serial.println("resetting");
        FastLED.addLeds<WS2812,DATA_PIN,RGB>(leds,NUM_LEDS);
        FastLED.setBrightness(24);
}

void fadeall() { for(int i = 0; i < NUM_LEDS; i++) { leds[i].nscale8(250); } }

void loop() { 
        static uint8_t hue = 0;
        Serial.print("x");
        // First slide the led in one direction
        for(int i = 0; i < NUM_LEDS; i++) {
                // Set the i'th led to red 
                leds[i] = CHSV(hue++, 255, 255);
                // Show the leds
                FastLED.show(); 
                // now that we've shown the leds, reset the i'th led to black
                // leds[i] = CRGB::Black;
                fadeall();
                // Wait a little bit before we loop around and do it again
                delay(10);
        }
        Serial.print("x");

        // Now go in the other direction.  
        for(int i = (NUM_LEDS)-1; i >= 0; i--) {
                // Set the i'th led to red 
                leds[i] = CHSV(hue++, 255, 255);
                // Show the leds
                FastLED.show();
                // now that we've shown the leds, reset the i'th led to black
                // leds[i] = CRGB::Black;
                fadeall();
                // Wait a little bit before we loop around and do it again
                delay(10);
        }
}

Arduino实验场景图

在这里插入图片描述

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/789640.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

【Postman】Postman接口测试进阶用法详解:断言、全局与环境变量、关联、批量执行用例、读取外部文件实现参数化

文章目录 一、Postman断言1、断言位置2、Postman的常用断言3、操作实例 二、全局变量与环境变量1、二者区分2、设置全局变量3、设置环境变量 三、Postman接口关联1、概念2、操作步骤 四、批量执行测试用例1、操作步骤2、查看结果 五、读取外部文件实现参数化1、使用场景2、操作…

云服务器远程nacos服务注册失败/不健康Client not connected, current status:STARTING

文章目录 Nacos报错docker安装不用 docker安装 Nacos报错 docker安装 使用docker在云服务器安装Nacos之后出现Client not connected, current status:STARTING 使用docker 安装之后需要添加映射端口 docker run -e JAVA_OPTS"-Xms256m -Xmx256m"-e MODEstandalone…

7.24 作业

1.自己封装vector template<typename T> class Myverctor {T* first;T* last;T* end; public:Myverctor():first(NULL),last(NULL),end(NULL){}Myverctor(int num,T data):first(new T[num]){last end first num;for(int i 0;i<num;i) first[i] data;}Myverctor…

【ROS2 Foxy】Rviz2 不支持可视化压缩图像消息

这里我通过订阅话题&#xff0c;压缩图像消息是存在的&#xff1a; ros2 topic echo /hk_camera/rgb/compressed从官方代码库的 issue 中了解到&#xff0c;在 Foxy 版本的 Rviz2 是不支持压缩图像消息的可视化的&#xff0c;现在 Foxy 也已经停止维护了&#xff0c;以后更不太…

redis 1

shell 1&#xff1a;安装1. 源码安装&#xff08;CENTOS&#xff09; 2.999:可能会出现得问题1. 编译出错 1&#xff1a;安装 1. 源码安装&#xff08;CENTOS&#xff09; 官方下载源码包 wget https://download.redis.io/redis-stable.tar.gz # 安装依赖 yum install gcc解压…

node 版本管理器 nvm

文章目录 一、卸载node二、nvm 下载三、nvm 安装四、检测环境变量是否一致五、nvm常见问题 一、卸载node 打开cmd命令行窗口&#xff0c;输入npm cache clean --force 回车执行 打开控制面板&#xff0c;在控制面板中把Node.js卸载 二、nvm 下载 nvm全英文也叫node.js ve…

7.25 Qt

制作一个登陆界面 login.pro文件 QT core guigreaterThan(QT_MAJOR_VERSION, 4): QT widgetsCONFIG c11# The following define makes your compiler emit warnings if you use # any Qt feature that has been marked deprecated (the exact warnings # depend on …

cocosCreator 之 ScrollView

版本&#xff1a;3.4.0 参考&#xff1a;ScrollView组件 简介 ScrollView组件作为滚动容器来使用&#xff0c;它的实现通过ScrollBar组件来展示内容的位置和Mask组件显示指定区域&#xff0c;来保证有限的区域内显示更多的内容。 它的构成部分&#xff1a; ScrollBar滚动条相…

3、Winform表单控件

在学习了布局控件之后,我们就该学习表单控件了。 程序的本质=输入+处理+输出。在Winform程序角度,这里的输入输出就可以用我们的表单控件来实现。 表单控件大致可分为两类,选项控件和文本控件。 文本控件 文本控件常用的有两种,分别是TextBox和RichTextBox TextBox T…

01 矩阵(力扣)多源广度优先搜索 JAVA

给定一个由 0 和 1 组成的矩阵 mat &#xff0c;请输出一个大小相同的矩阵&#xff0c;其中每一个格子是 mat 中对应位置元素到最近的 0 的距离。 两个相邻元素间的距离为 1 。 输入&#xff1a;mat [[0,0,0],[0,1,0],[0,0,0]] 输出&#xff1a;[[0,0,0],[0,1,0],[0,0,0]] 输入…

修改小说阅读器

感谢这个作者的插件&#xff1a;https://ext.dcloud.net.cn/plugin?id2485 1. 搬入后page TypeError: Cannot read property page of undefined 该问题已经解决&#xff0c;有两种方法。第一种&#xff1a;直接注释掉 &#xff0c;第二种 修改为vue3的方式 // 取消ios左滑返…

数据结构和算法一(空间复杂度、时间复杂度等算法入门)

时间复杂度&#xff1a; 空间复杂度&#xff1a; 时间比空间重要 递归&#xff1a; 递归特征&#xff1a; 递归案例&#xff1a; 汉诺塔问题&#xff1a; def hanoi(n,A,B,C):if n>0:hanoi(n-1,A,C,B)print("moving from %s to %s"%(A,C))hanoi(n-1,B,A,C)hanoi…

java中的动态代理机制

目录 什么是动态代理&#xff1f; 为什么需要代理&#xff1f; 代理长什么样子&#xff1f; 代码样例 什么是动态代理&#xff1f; 动态代理可以无侵入式的给代码增加功能 为什么需要代理&#xff1f; 对象如果嫌弃身上的事情太多&#xff0c;就可以通过代理来转移部分的…

STC12C5A系列单片机内部 EEPROM 的应用

参考范例程序。 eeprom.c #include "eeprom.h"/*---------------------------- Disable ISP/IAP/EEPROM function Make MCU in a safe state ----------------------------*/ void IapIdle() {IAP_CONTR 0; //Close IAP functionIAP_CMD 0; …

vue中Swiper动态渲染swiper-slide后轮播图呆滞划不动的问题

因项目开发中很多都有用到轮播图的地方&#xff0c;然后选择用了swiper&#xff0c;记录一下&#xff0c;之前一直没有发布这个文章&#xff0c;现在官方好像已经优化了这个问题。 下载引入&#xff0c;具体参考官方文档Swiper演示 - Swiper中文网 问题描述&#xff1a;在图片…

HiVT、VectorNet运动预测方法分析

1. VectorNet原理 基于DL的运动预测方法有基于渲染的方法和基于坐标点编码的方法&#xff1a;基于渲染的方法通过将交通要素渲染成一张特征图&#xff0c;再基于CNN等网络对特征进行学习&#xff0c;实现目标对象未来轨迹预测。基于交通要素渲染成特征图方法存在CPU算力需求大…

MySQL语句通过腾讯云数据库智能管家的性能与语法优化

最近公司项目迁移至腾讯云&#xff0c;用的腾讯云MySQL服务器&#xff0c;MySQL负载一直很高&#xff0c;借助云管家优化了一部分SQL语句&#xff0c;提升了部分性能和释放了部分&#xff0c;MySQL内存占用

redis(10):spring+redis+mysql缓存实现

1 新建spring项目 2 修改pom.xml <?xml version"1.0" encoding"UTF-8"?> <project xmlns"http://maven.apache.org/POM/4.0.0"xmlns:xsi"http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation"http://mav…

IOC学习笔记(上篇)

IOC学习笔记&#xff08;上篇&#xff09; 目录 IOC容器的职责Ioc容器的实现传统IoC容器的实现依赖查找VS依赖注入构造器注入VS Setter注入面试题 1. 什么是IOC&#xff1f;2. 依赖查找和依赖注入的区别3. Spring作为IOC容器有什么优势 学习视频地址&#xff1a;https://ti…

10分钟搭建链路追踪平台

随着项目越来越多&#xff0c;相互调用越来越复杂&#xff0c;搭建一个可视化的链路追踪平台显得尤为重要&#xff0c;今天给大家介绍的是zipkin&#xff0c;一个轻量级的零侵入的链路追踪平台&#xff0c;看我怎么10分钟给大家搭建出来。 1&#xff0c;介绍 zipkin官网&…