ARDUINO UNO 12颗LED超酷流水灯效果

效果代码:

#define t 30

#define t1 20

#define t2 100

#define t3 50

void setup() {

// set up pins 2 to 13 as outputs

for (int i = 2; i <= 13; i++) {

pinMode(i, OUTPUT);

}

}

/Effect 1

void loop()

{

effect_1();

effect_1();

effect_2();

effect_2();

effect_3();

effect_3();

effect_4();

effect_4();

effect_5();

effect_5();

effect_6();

effect_6();

effect_7();

effect_7();

}

//左到右右到左

void effect_1()

{

for(int i=2; i<14; i++){

digitalWrite(i, HIGH);

delay(t1);

digitalWrite(i+1, HIGH);

delay(t1);

digitalWrite(i+2, HIGH);

delay(t1);

digitalWrite(i, LOW);

delay(t1);

digitalWrite(i+1, LOW);

delay(t1);

}

for(int i=13; i>1; i--){

digitalWrite(i, HIGH);

delay(t1);

digitalWrite(i-1, HIGH);

delay(t1);

digitalWrite(i-2, HIGH);

delay(t1);

digitalWrite(i, LOW);

delay(t1);

digitalWrite(i-1, LOW);

delay(t1);

}

}

/Effect 2

void effect_2()

{

int count = 13; // keeps track of second LED movement

// 将第一个 LED 从左向右移动,第二个 LED 从右向左移动

for (int i = 2; i < 13; i++) {

clear();

digitalWrite(i, HIGH); // chaser 1

digitalWrite(count, HIGH); // chaser 2

count--;

// 停止 LED ,静止在中间

if (count != 7) {

delay(t2);

}

}

// 将第一个 LED 从右向左移动,将第二个 LED 从左向右移动

for (int i = 13; i > 2; i--) {

clear();

digitalWrite(i, HIGH); // chaser 1

digitalWrite(count, HIGH); // chaser 2

count++;

// 停止 LED ,静止在中间

if (count != 8) {

delay(t2);

}

}

}

Effect 3

void effect_3()

{

for(int i=2; i<14; i++){

digitalWrite(i, HIGH);

delay(t3);

}

for(int i=2; i<14; i++){

digitalWrite(i, LOW);

delay(t3);

}

for(int i = 14; i>=2; i--){

digitalWrite(i, HIGH);

delay(t3);

}

for(int i = 14; i>=2; i--){

digitalWrite(i, LOW);

delay(t3);

}

}

///Effect 4

void effect_4()

{

for(int j = 2; j <= 13; j++){

digitalWrite(j, HIGH);

delay(t2);

j=j+1;

}

for(int j = 2; j <= 13; j++){

digitalWrite(j, LOW);

delay(t2);

}

for(int k = 15; k > 2; k--){

digitalWrite(k, HIGH);

delay(t2);

k=k-1;

}

for(int k = 15; k > 2; k--){

digitalWrite(k, LOW);

delay(t2);

}

}

//Effect 5

void effect_5()

{

clear();

for (int i = 2; i < 13; i++) {

for (int pin = 13; pin >= i; pin--)

{

digitalWrite(pin, HIGH);

delay(t1);

digitalWrite(pin + 1, LOW);

delay(t1);

}

}

}

/Effect 6

void effect_6()

{

for(int j=2; j<14; j++){

digitalWrite(j, LOW);

delay(t);

digitalWrite(j, HIGH);

delay(t);

digitalWrite(j-2, LOW);

delay(t);

digitalWrite(j, HIGH);

}

for(int k = 15; k>2; k--){

digitalWrite(k, LOW);

delay(t);

digitalWrite(k, HIGH);

delay(t);

digitalWrite(k+2, LOW);

delay(t);

digitalWrite(k, HIGH);

}

for(int k = 2; k<14; k++){

digitalWrite(k, LOW);

delay(t);

digitalWrite(k, HIGH);

delay(t);

digitalWrite(k-2, LOW);

delay(t);

digitalWrite(k, HIGH);

}

for(int k = 15; k>2; k--){

digitalWrite(k, LOW);

delay(t);

digitalWrite(k, HIGH);

delay(t);

digitalWrite(k+4, LOW);

delay(t);

digitalWrite(k, HIGH);

}

for(int k = 2; k<14; k++){

digitalWrite(k, LOW);

delay(t);

digitalWrite(k, HIGH);

delay(t);

digitalWrite(k-4, LOW);

delay(t);

digitalWrite(k, HIGH);

}

}

///Effect 7

void effect_7()

{

for(int j=2; j<14; j++){

digitalWrite(j, HIGH);

delay(t);

digitalWrite(j+2, LOW);

delay(t);

}

for(int k = 15; k>2; k--){

digitalWrite(k, HIGH);

delay(t);

digitalWrite(k+2, LOW);

delay(t);

}

}

// function to switch all LEDs off

void clear(void)

{

for (int i = 2; i <= 13; i++) {

digitalWrite(i, LOW);

}

}

相关推荐
pianmian14 小时前
python数据结构基础(7)
数据结构·算法
好奇龙猫6 小时前
【学习AI-相关路程-mnist手写数字分类-win-硬件:windows-自我学习AI-实验步骤-全连接神经网络(BPnetwork)-操作流程(3) 】
人工智能·算法
sp_fyf_20246 小时前
计算机前沿技术-人工智能算法-大语言模型-最新研究进展-2024-11-01
人工智能·深度学习·神经网络·算法·机器学习·语言模型·数据挖掘
ChoSeitaku7 小时前
链表交集相关算法题|AB链表公共元素生成链表C|AB链表交集存放于A|连续子序列|相交链表求交点位置(C)
数据结构·考研·链表
偷心编程7 小时前
双向链表专题
数据结构
香菜大丸7 小时前
链表的归并排序
数据结构·算法·链表
jrrz08287 小时前
LeetCode 热题100(七)【链表】(1)
数据结构·c++·算法·leetcode·链表
oliveira-time7 小时前
golang学习2
算法
@小博的博客7 小时前
C++初阶学习第十弹——深入讲解vector的迭代器失效
数据结构·c++·学习
南宫生8 小时前
贪心算法习题其四【力扣】【算法学习day.21】
学习·算法·leetcode·链表·贪心算法