【Proteus仿真】【Arduino单片机】RGB彩灯

2023-11-03 09:36

本文主要是介绍【Proteus仿真】【Arduino单片机】RGB彩灯,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

文章目录

  • 一、功能简介
  • 二、软件设计
  • 三、实验现象
  • 联系作者


一、功能简介

本项目使用Proteus8仿真Arduino单片机控制器,使用WS2812 RGB彩灯等。
主要功能:
系统运行后,RGB彩灯花样显示。


二、软件设计

/*
作者:嗨小易(QQ:3443792007)*/#include "public.h"
#include <Adafruit_NeoPixel.h>// Which pin on the Arduino is connected to the NeoPixels?
// On a Trinket or Gemma we suggest changing this to 1:
#define LED_PIN     6// How many NeoPixels are attached to the Arduino?
#define LED_COUNT  32// NeoPixel brightness, 0 (min) to 255 (max)
#define BRIGHTNESS 250 // Set BRIGHTNESS to about 1/5 (max = 255)// Declare our NeoPixel strip object:
Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRBW + NEO_KHZ800);
// Argument 1 = Number of pixels in NeoPixel strip
// Argument 2 = Arduino pin number (most are valid)
// Argument 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)void setup() {strip.begin();           // INITIALIZE NeoPixel strip object (REQUIRED)strip.show();            // Turn OFF all pixels ASAPstrip.setBrightness(BRIGHTNESS);
}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(1000); // 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(500); // Pause 1/2 second
}

三、实验现象

B站演示视频:https://space.bilibili.com/444388619

在这里插入图片描述

联系作者

视频地址:https://space.bilibili.com/444388619/video
专注于51单片机、STM32、国产32、DSP、Proteus、arduino、ESP32、物联网软件开发,PCB设计,视频分享,技术交流。

这篇关于【Proteus仿真】【Arduino单片机】RGB彩灯的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/337265

相关文章

基于UE5和ROS2的激光雷达+深度RGBD相机小车的仿真指南(五):Blender锥桶建模

前言 本系列教程旨在使用UE5配置一个具备激光雷达+深度摄像机的仿真小车,并使用通过跨平台的方式进行ROS2和UE5仿真的通讯,达到小车自主导航的目的。本教程默认有ROS2导航及其gazebo仿真相关方面基础,Nav2相关的学习教程可以参考本人的其他博客Nav2代价地图实现和原理–Nav2源码解读之CostMap2D(上)-CSDN博客往期教程: 第一期:基于UE5和ROS2的激光雷达+深度RG

基于51单片机的自动转向修复系统的设计与实现

文章目录 前言资料获取设计介绍功能介绍设计清单具体实现截图参考文献设计获取 前言 💗博主介绍:✌全网粉丝10W+,CSDN特邀作者、博客专家、CSDN新星计划导师,一名热衷于单片机技术探索与分享的博主、专注于 精通51/STM32/MSP430/AVR等单片机设计 主要对象是咱们电子相关专业的大学生,希望您们都共创辉煌!✌💗 👇🏻 精彩专栏 推荐订阅👇🏻 单片机

arduino ide安装详细步骤

​ 大家好,我是程序员小羊! 前言: Arduino IDE 是一个专为编程 Arduino 微控制器设计的集成开发环境,使用起来非常方便。下面将介绍如何在不同平台上安装 Arduino IDE 的详细步骤,包括 Windows、Mac 和 Linux 系统。 一、在 Windows 上安装 Arduino IDE 1. 下载 Arduino IDE 打开 Arduino 官网

单片机毕业设计基于单片机的智能门禁系统的设计与实现

文章目录 前言资料获取设计介绍功能介绍程序代码部分参考 设计清单具体实现截图参考文献设计获取 前言 💗博主介绍:✌全网粉丝10W+,CSDN特邀作者、博客专家、CSDN新星计划导师,一名热衷于单片机技术探索与分享的博主、专注于 精通51/STM32/MSP430/AVR等单片机设计 主要对象是咱们电子相关专业的大学生,希望您们都共创辉煌!✌💗 👇🏻 精彩专栏 推荐订

perl的学习记录——仿真regression

1 记录的背景 之前只知道有这个强大语言的存在,但一直侥幸自己应该不会用到它,所以一直没有开始学习。然而人生这么长,怎就确定自己不会用到呢? 这次要搭建一个可以自动跑完所有case并且打印每个case的pass信息到指定的文件中。从而减轻手动跑仿真,手动查看log信息的重复无效低质量的操作。下面简单记录下自己的思路并贴出自己的代码,方便自己以后使用和修正。 2 思路整理 作为一个IC d

文章解读与仿真程序复现思路——电力自动化设备EI\CSCD\北大核心《考虑燃料电池和电解槽虚拟惯量支撑的电力系统优化调度方法》

本专栏栏目提供文章与程序复现思路,具体已有的论文与论文源程序可翻阅本博主免费的专栏栏目《论文与完整程序》 论文与完整源程序_电网论文源程序的博客-CSDN博客https://blog.csdn.net/liang674027206/category_12531414.html 电网论文源程序-CSDN博客电网论文源程序擅长文章解读,论文与完整源程序,等方面的知识,电网论文源程序关注python

基于stm32的河流检测系统-单片机毕业设计

文章目录 前言资料获取设计介绍功能介绍具体实现截图参考文献设计获取 前言 💗博主介绍:✌全网粉丝10W+,CSDN特邀作者、博客专家、CSDN新星计划导师,一名热衷于单片机技术探索与分享的博主、专注于 精通51/STM32/MSP430/AVR等单片机设计 主要对象是咱们电子相关专业的大学生,希望您们都共创辉煌!✌💗 👇🏻 精彩专栏 推荐订阅👇🏻 单片机设计精品

Matlab simulink建模与仿真 第十章(模型扩展功能库)

参考视频:simulink1.1simulink简介_哔哩哔哩_bilibili 一、模型扩展功能库中的模块概览         注:下面不会对Block Support Table模块进行介绍。 二、基于触发的和基于时间的线性化模块 1、Trigger-Based Linearization基于触发的线性化模块 (1)每次当模块受到触发时,都会调用linmod或者dlinmod函数

VB和51单片机串口通信讲解(只针对VB部分)

标记:该篇文章全部搬自如下网址:http://www.crystalradio.cn/thread-321839-1-1.html,谢谢啦            里面关于中文接收的部分,大家可以好好学习下,题主也在研究中................... Commport;设置或返回串口号。 SettingS:以字符串的形式设置或返回串口通信参数。 Portopen:设置或返回串口

AMEsim和Simulink联合仿真生成新的.mexw64液压模型文件

AMEsim和Simulink进行联合仿真非常重要的就是AMEsim经过第四阶段Simulation会在相同文件下面生成一个与AMEsim液压模型相同名字的.mexw64文件,在Simulink进行联合仿真的S-Function需要找的也就是这个文件,只不过输入的时候除了液压模型名字之外,后面有一个短下划线。 简而言之: AMEsim和Simulink联合仿真, 首先是需要AMEsim软