【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.hqwc.cn/news/158321.html

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

相关文章

APUS成为深圳市人工智能行业协会理事单位,CEO李涛受聘专家

近日&#xff0c;APUS正式成为深圳市人工智能行业协会理事单位&#xff0c;APUS董事长兼CEO李涛同时受聘为协会专家委员会专家。 深圳市人工智能行业协会成立于2017年&#xff0c;由电子通信、大数据、计算机视觉、自然语言处理等AI相关领域企事业单位组成&#xff0c;致力于加…

使用IDEA生成JavaDoc文档(IDEA2023)

1、Tool-->Generate JavaDoc 2、配置生成JavaDoc文档 1、选择生成范围&#xff0c;可以根据需要选择单独一个文件或者包&#xff0c;也可以是整个项目 2、输出目录&#xff0c;要把JavaDoc文档生成在哪个文件中&#xff0c;最好新建一个文件夹结束 3、Local&#xff1a;…

OpenGL_Learn04

我这边并不是教程&#xff0c;只是学习记录&#xff0c;方便后面回顾&#xff0c;代码均是100%可以运行成功的。 1. 渐变三角形 #include <glad/glad.h> #include <GLFW/glfw3.h>#include <iostream> #include <cmath>void framebuffer_size_callba…

代码随想录Day32 动态规划01 LeetCodeT509 斐波那契数列 T70 爬楼梯 T746 爬楼梯的最小消耗

前言:动态规划基础 动态规划首先可以解决的问题有背包问题,打家劫舍问题,股票问题,子序列问题等,主要是将一个大的问题切分成多个重叠的子问题,所以动态规划一定是上一个状态递推过来的,有一个重要的状态转移方程,但是这也并不是解题的全部,我们将动态规划的题目基本分为五步来…

【Kubernetes部署】二进制部署单Master Kurbernetes集群 超详细

二进制部署K8s 一、基本架构和系统初始化操作1.1 基本架构1.2 系统初始化操作 二、部署etcd集群2.1 证书签发Step1 下载证书制作工具Step2 创建k8s工作目录Step3 编写脚本并添加执行权限Step4 生成CA证书、etcd 服务器证书以及私钥 2.2 启动etcd服务Step1 上传并解压代码包Step…

Git客户端软件 Tower mac中文版特点说明

Tower mac是一款Mac OS X系统上的Git客户端软件&#xff0c;它提供了丰富的功能和工具&#xff0c;帮助用户更加方便地管理和使用Git版本控制系统。 Tower mac软件特点 1. 界面友好&#xff1a;Tower的界面友好&#xff0c;使用户能够轻松地掌握软件的使用方法。 2. 多种Git操…

Redis之持久化(RDB和AOF)

文章目录 前言一、RDB1.介绍2.redis.config有关配置3.触发4.恢复5.优缺点 二、AOF1.介绍2.redis.config配置3.启动4.恢复5.重写6.优缺点 总结 前言 Redis 是内存数据库&#xff0c;即数据存储在内存。 如果不将内存中的数据保存到磁盘&#xff0c;一旦服务器进程退出&#xff…

2023年科技革新:引领行业走向未来的十大技术趋势

随着时间的推移&#xff0c;2023年展现出了科技领域的一系列令人瞩目的新发现和趋势。这些新兴技术不仅推动了各行各业的发展&#xff0c;还为解决当今社会面临的诸多挑战提供了新的视角和解决方案。在这篇文章中&#xff0c;我们将探讨一些可能会改变行业面貌的关键技术趋势。…

arcgis图上添加发光效果!

看完本文, 你可以不借助外部图片素材, 让你的图纸符号表达出你想要的光! 我们以之前的某个项目图纸为例,来介绍下让符号发光的技术! 第一步—底图整理 准备好栅格影像底图、行政边界的矢量数据,确保“数据合适、位置正确、边界吻合”。 确定好图纸的大小、出图比例、投…

Thinkphp6项目在虚拟机无法指向pulic的目录访问的方法

以阿里云虚拟主机为例&#xff0c;服务器环境为 LAMP&#xff0c;Apache2.4 php7.2 mysql5.7 1.根目录新建 index.php 文件&#xff0c;将以下内容放入文件中 <?php include ./public/index.php;2.将 public 目录下的 admin.php、backend 文件夹、static 文件夹、tinymc…

计算机毕业设计选题推荐-招聘信息推荐系统-Python项目实战

✨作者主页&#xff1a;IT研究室✨ 个人简介&#xff1a;曾从事计算机专业培训教学&#xff0c;擅长Java、Python、微信小程序、Golang、安卓Android等项目实战。接项目定制开发、代码讲解、答辩教学、文档编写、降重等。 ☑文末获取源码☑ 精彩专栏推荐⬇⬇⬇ Java项目 Python…

微服务框架SpringcloudAlibaba+Nacos集成RabbitMQ

目前公司使用jeepluscloud版本&#xff0c;这个版本没有集成消息队列&#xff0c;这里记录一下&#xff0c;集成的过程&#xff1b;这个框架跟ruoyi的那个微服务版本结构一模一样&#xff0c;所以也可以快速上手。 1.项目结构图&#xff1a; 配置类的东西做成一个公共的模块 …