【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设计,视频分享,技术交流。

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

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

相关文章

【VS Code】使用 VS Code 登陆远程服务器上的 Docker 容器

以下命令默认已经构建了一个 Docker Image。 # 在服务器上启动 docker (-p 端口映射&#xff0c;用于后续的 ssh 连接) docker run -itd -v /mnt/mount/:/home -p 8124:22 --name container-name --gpus all image-name# 进入容器中 docker exec -it container-name /bin/bas…

如何通过智能管理箱实现高效文件管理:关键字轻松修改文件名

在信息化时代&#xff0c;文件管理变得尤为重要。智能管理箱已经成为我们生活中不可或缺的一部分。它可以帮助我们高效地管理各种文件&#xff0c;使得我们的工作和生活更加便捷。是一种高效的文件管理工具&#xff0c;可以帮助我们轻松地整理和分类文件&#xff0c;提高工作效…

【MediaFoundation】读取音视频

原文链接&#xff1a; 官方文档 Microsoft Media Foundation支持音频和视频捕获。视频捕获设备通过UVC类驱动程序支持&#xff0c;并必须与UVC 1.1兼容。音频捕获设备通过Windows音频会话API&#xff08;WASAPI&#xff09;支持。 在Media Foundation中&#xff0c;捕获设备通…

Linux - 进程控制(下篇)- 进程等待

进程等待 为什么进程需要等待&#xff1f; 我们知道&#xff0c;在Linux 当中&#xff0c;父子进程之间一些结构就是一些多叉树的结构&#xff0c;一个父进程可能管理或者创建了很多个字进程。 而其实我们在代码当中使用fork&#xff08;&#xff09;函数创建的子进程的父进程…

模型训练----对输入变量原地操作(inplace operation)报错

遇到报错one of the variables needed for gradient computation has been modified by an inplace operation。意思是对输入x原地操作&#xff08;inplace operation&#xff09;&#xff0c;一个变量在反向传播过程中被修改了&#xff0c;而不是按照预期的版本&#xff08;ve…

vivo发布“蓝心千询”自然语言对话机器人

&#x1f989; AI新闻 &#x1f680; vivo发布“蓝心千询”自然语言对话机器人 摘要&#xff1a;vivo今日发布了“蓝心千询”自然语言对话机器人&#xff0c;基于蓝心大模型。蓝心千询可以进行知识信息的快速问答&#xff0c;文学创作、图片生成&#xff0c;甚至还能编写程序…

C语言基础知识

C语言基础知识 1. 基本数据类型2. 变量和常量3. 运算符4. 条件语句和循环5. 函数 C语言是一种广泛使用的计算机编程语言&#xff0c;由丹尼斯里奇&#xff08;Dennis Ritchie&#xff09;于1972年在贝尔实验室发明。C语言是一种高级语言&#xff0c;因为它允许使用更抽象的语法…

mit6.s081 笔记

1、系统调用 系统调用具体过程。 在任何地方&#xff0c;当我们需要使用系统调用时&#xff0c;只需要include “user/user.h”&#xff0c;就可以通过里面的函数声明来调系统调用&#xff0c;其函数的具体实现由 user/usys.pl 脚本帮我们生成对应的汇编代码&#xff08;具体代…

ENVI波段合成

1、envi5.3合成&#xff08;这种方法&#xff0c;必须有地理参考才可以&#xff09; 在工具栏处搜索波段&#xff0c;找到波段合成&#xff08;Layer Stacking&#xff09; 设置合成波段&#xff0c;其他默认 2、envi classic&#xff08;没有地理坐标也可以&#xff09; 我们…

https网站加载http资源问题

https网站加载http资源问题 前言&#xff1a;最近项目对接了一个第三方的平台、我们需要展示第三方平台返回来的图片资源、由于我们的服务器设置为了https、但是第三方平台返回的图片链接是 http 资源。所以就出现了图片无法加载出来的问题&#xff0c;在此记录一下问题的解决…

Java日期比较大小的3种方式及拓展

目录 一、字符串String的日期比较 二、数值型long比较 三、日期型Date直接比较 四、Date型日期的获取方式 五、Calendar获取年月日【拓展】 一、字符串String的日期比较 String型的日期通过compareTo()来比较&#xff0c;因为String实现了comparable接口 endDate.compare…

右击文件或者文件夹使用vscode打开

平常我们在打开项目时&#xff0c;经常会需要快捷打开方式&#xff0c;直接使右键使用编辑器打开&#xff0c;但是有时在安装时忘记了选择 “Add “Open with Code” action to Windows Explorer file context menu” 在Windows资源管理器文件上下文菜单中添加“用代码打开”操…

Xcode 14.3 新版问题总结

1. "xxx/IntermediateBuildFilesPath/UninstalledProducts/iphoneos/xxxx" failed: No such file or directory 解决&#xff1a;Pods/Targets Support Files/Pods-App-frameworks.sh中 if [ -L "${source}" ]; thenecho "Symlinked..."# sour…

HttpClient基本使用

十二、HttpClient 12.1 介绍 HttpClient是Apache Jakarta Common 下的子项目&#xff0c;可以用来提供高效的、最新的、功能丰富的支持HTTP协议的客户端编程工具包&#xff0c;并且它支持HTTP协议最新的版本和建议。 HttpClient作用&#xff1a; 发送HTTP请求接收响应数据 …

Jtti:redis出现太多连接错误怎么解决

Redis出现太多连接错误通常是由于一些常见问题引起的&#xff0c;这些问题可能会导致连接超限、性能下降或服务不可用。以下是一些可能导致Redis连接错误的原因以及如何解决它们的建议&#xff1a; 1. 连接泄漏&#xff1a; 连接泄漏是指在使用完Redis连接后没有正确关闭它们。…

1-10 HTML中input属性

HTML中input属性 text&#xff1a;用于接受单行文本输入password&#xff1a;用于密码输入&#xff0c;输入字符会被掩盖radio&#xff1a;用于单选按钮&#xff0c;用户可以在一组选项中选择一个checkbox&#xff1a;用于复选框&#xff0c;用户可以选择多个选项number&#…

有效的括号

给定一个只包括 ‘(’&#xff0c;‘)’&#xff0c;‘{’&#xff0c;‘}’&#xff0c;‘[’&#xff0c;‘]’ 的字符串 s &#xff0c;判断字符串是否有效。 有效字符串需满足&#xff1a; 左括号必须用相同类型的右括号闭合。左括号必须以正确的顺序闭合。每个右括号都有…

Django 表单处理:从前端到后台的全流程指南

Django作为一个高级Python Web框架&#xff0c;它的表单处理能力强大&#xff0c;可以有效地处理用户输入&#xff0c;进行数据验证以及错误处理。本文将详细介绍如何在Django中创建、处理和使用表单。 1. Django表单系统的核心 Django的表单系统处理表单的生命周期&#xff…

Python之字符串详解

目录 一、字符串1、转义字符与原始字符串2、使用%运算符进行格式化 一、字符串 在Python中&#xff0c;字符串属于不可变、有序序列&#xff0c;使用单引号、双引号、三单引号或三双引号作为定界符&#xff0c;并且不同的定界符之间可以互相嵌套。 ‘abc’、‘123’、‘中国’…

MySQL:一文掌握MySQL索引

目录 概念优缺点索引的数据结构Hash索引有序数组索引二叉搜索树平衡二叉树B树B树 索引的物理结构MyISAM存储引擎InnoDB存储引擎 索引的分类页、区、段change buffer 和索引回表和覆盖索引索引优化面试题索引哪些情况下会失效什么是索引下推主键选择自增和uuid的区别 概念 官方…