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

  • 相关阅读:
    【顺序程序设计-谭浩强适配】(适合专升本、考研)
    SpringBoot官方支持任务调度框架,轻量级用起来也挺香!
    免费api接口集合分享,再也不怕找不到免费api了
    Kubernetes部署(八):k8s项目交付----(5)持续部署
    认识线程栈与托管堆
    python(自5)scrapy下载安装 基本使用
    嵌入式 Linux 入门 环境篇(三、开发板和 PC 的网络互通)
    【Linux基础】工作中常用的linux命令,经常会被面试官问到
    用DIV+CSS技术设计的美食主题网站(web前端网页制作课作业)美食餐饮网站设计与实现(HTML+CSS+JavaScript)
    15个Java线程并发面试题和答案
  • 原文地址:https://blog.csdn.net/sxstj/article/details/134482578