Новогодние огоньки

Emeljanowich
Emeljanowich аватар
Offline
Зарегистрирован: 30.04.2015

Привет, друзья! Представляю вашему вниманию проект новогодних гирлянд. Проект очень простой. Одна ножка мк зажигает одну группу светодиодов и делает это с помощью ULN2003. И того три линии по 7 групп в каждой. Включив фантазию, можно как  угодно, в любой последовательности их зажигать, и, тем самым, создавать новогоднее нестроение себе и другим! Удачи в Новом году!)

byte l[] = {15, 16, 17, 18, 19, 20, 21}; //левый
byte r[] = {30, 29, 28, 27, 26, 25, 24}; //правый
byte c[] = {14, 13, 12, 11, 10, 9, 8};

byte i = 0;
byte j = 0;
byte s = 0;
byte w = 7;
unsigned int z;



void setup() {
  for (byte i = 0; i < 7; i++) {pinMode(l[i], OUTPUT); pinMode(r[i], OUTPUT); pinMode(c[i], OUTPUT);} 
  pinMode(0, INPUT); digitalWrite(0, HIGH);
}


void loop() {
  if (digitalRead(0) == 0) {delay(200); i++; if (i > 9) i = 0;      } 
    switch(i){
      case 0: for (byte a = 0; a < 7; a++) {digitalWrite(l[a], HIGH); digitalWrite(r[a], HIGH); digitalWrite(c[a], HIGH);}
              j = j - 5; z = j*5; if (j <= 50) {j = 0; s++;} if (s > 2) {s = 0; z = 0; i = 1;}
              delay(z);
              for (byte a = 0; a < 7; a++) {digitalWrite(l[a], LOW); digitalWrite(r[a], LOW); digitalWrite(c[a], LOW);}
              delay(z);
        break;

      case 1: for (byte a = 0; a < 7; a++) { digitalWrite(l[a], HIGH); digitalWrite(r[a], HIGH); delay(160); digitalWrite(l[a], LOW); digitalWrite(r[a], LOW);}
              for (byte a = 4; a < 7; a++) {digitalWrite(c[a], HIGH); delay(160); digitalWrite(c[a], LOW);}
              for (byte a = 0; a < 4; a++) {digitalWrite(c[a], HIGH);}
              delay(1000);
              for (byte a = 0; a < 7; a++) {digitalWrite(c[a], LOW);}
              j++; if (j > 60) {s++; j = 0;} if (s > 2) {s = 0; j = 0; i = 2;}
        break;

      case 2: for (byte a = 0; a < 4; a++) {digitalWrite(c[a], HIGH);}
              for (byte a = 0; a < 7; a++) {digitalWrite(l[a], HIGH); digitalWrite(r[a], HIGH); delay(80); digitalWrite(l[a], LOW); digitalWrite(r[a], LOW);}
              for (byte a = 0; a < 7; a++) {digitalWrite(l[6-a], HIGH); digitalWrite(r[6-a], HIGH); delay(80); digitalWrite(l[6-a], LOW); digitalWrite(r[6-a], LOW);}
              j++; if (j > 80) {s++; j = 0;} if (s == 3) {s = 0; j = 0; i = 3;}
        break;

      case 3: for (byte a = 0; a < 7; a++) {digitalWrite(c[a], HIGH);}
              for (byte a = 0; a < w; a++) {digitalWrite(l[a], HIGH); digitalWrite(r[a], HIGH); delay(100); digitalWrite(l[a], LOW); digitalWrite(r[a], LOW);}
              w--; digitalWrite(l[w], HIGH); digitalWrite(r[w], HIGH);  
              if (w == 0) {delay(1000); for (byte a = 0; a < 7; a++) {digitalWrite(c[a], LOW); digitalWrite(r[a], LOW); digitalWrite(l[a], LOW);} delay(1500);
              s++; if (s > 80) {s = 0; j = 0; i = 4;} w = 7;}
        break;     
        
      case 4: for (byte a = 0; a < 7; a++) {digitalWrite(r[a], HIGH); digitalWrite(l[a], HIGH); delay(150);}
              delay(1000);
              for (byte a = 0; a < 7; a++) {digitalWrite(c[a], HIGH); delay(150);}
              delay(1000);
              for (byte a = 0; a < 7; a++) {digitalWrite(r[6-a], LOW); digitalWrite(l[6-a], LOW); delay(150);}
              delay(1000);
              for (byte a = 0; a < 7; a++) {digitalWrite(c[6-a], LOW); delay(150);}
              delay(1000);
              j++; if (j > 12) {s++; j = 0;} if (s > 1) {s = 0; j = 0; i = 5;}
        break;      
      
      case 5: for (byte a = 0; a < 7; a++) {digitalWrite(c[a], HIGH); delay(140); digitalWrite(c[a], LOW);}
              for (byte a = 0; a < 7; a++) {digitalWrite(c[6-a], HIGH); delay(140); digitalWrite(c[6-a], LOW);}
              w--;
              digitalWrite(l[w], HIGH); digitalWrite(r[w], HIGH); delay(700);
              if (w == 0) {for (byte a = 0; a < 7; a++) {digitalWrite(r[a], LOW); digitalWrite(l[a], LOW);} delay(600);
              s++; if (s > 30) {s = 0; j = 0; i = 6;} w = 7;}
        break;

      case 6: for (byte a = 0; a < 4; a++) {digitalWrite(c[a], HIGH);}
              for (byte a = 4; a < 7; a++) {digitalWrite(c[a], HIGH); delay(200); digitalWrite(c[a], LOW);}
              for (byte a = 0; a < w; a++) {digitalWrite(l[a], HIGH); digitalWrite(r[a], HIGH); delay(120); digitalWrite(l[a], LOW); digitalWrite(r[a], LOW);}
              w--; digitalWrite(l[w], HIGH); digitalWrite(r[w], HIGH); 
              delay(400);
              if (w == 0) {delay(800); for (byte a = 0; a < 7; a++) {digitalWrite(c[a], LOW); digitalWrite(r[a], LOW); digitalWrite(l[a], LOW);} delay(1000);
              s++; if (s > 30) {s = 0; j = 0; i = 7;} w = 7;}
        break;

      case 7: for (byte a = 0; a < 7; a++) {digitalWrite(r[6-a], HIGH); delay(150);} 
              for (byte a = 0; a < 7; a++) {digitalWrite(l[a], HIGH); delay(150);}
              for (byte a = 0; a < 7; a++) {digitalWrite(r[6-a], LOW); delay(150);} 
              for (byte a = 0; a < 7; a++) {digitalWrite(l[a], LOW); delay(150);}
              j++; if (j > 20) {s++; j = 0;} if (s == 2) {s = 0; j = 0; i = 8;}
        break;

      case 8: for (byte a = 0; a < 7; a++) {digitalWrite(r[a], HIGH); digitalWrite(l[a], HIGH);  delay(120); digitalWrite(r[a], LOW); digitalWrite(l[a], LOW);} 
              j++; if (j > 150) {s++; j = 0;} if (s > 3) {s = 0; j = 0; i = 9;}
        break;
        
      case 9: for (byte a = 0; a < w; a++) {digitalWrite(l[a], HIGH); digitalWrite(r[a], HIGH); delay(120); digitalWrite(l[a], LOW); digitalWrite(r[a], LOW);}
              w--; 
              digitalWrite(l[w], HIGH); digitalWrite(r[w], HIGH); 
              delay(400);
              if (w == 0) {for (byte a = 0; a < 7; a++) {digitalWrite(c[a], HIGH); s++; i = 10;}}
        break;
        
      case 10: for (byte a = 0; a < w; a++) {digitalWrite(l[a], HIGH); digitalWrite(r[a], HIGH); delay(150); digitalWrite(l[a], LOW); digitalWrite(r[a], LOW);}
               digitalWrite(l[w], LOW); digitalWrite(r[w], LOW); 
               w++;
               delay(400);
               if (w == 7) {for (byte a = 0; a < 7; a++) {digitalWrite(c[a], LOW);}}
               if (s > 8) {i = 11; s = 0; w = 7;} else i = 9;
        break;

      case 11: for (byte a = 0; a < 7; a++) {digitalWrite(l[a], HIGH); digitalWrite(r[a], HIGH); digitalWrite(c[a], HIGH); delay(200);}
               for (byte a = 0; a < 7; a++) {digitalWrite(l[a], LOW); digitalWrite(r[a], LOW); digitalWrite(c[a], LOW); delay(100);} 
               delay(400);
               j++; if (j > 15) {s++; j = 0;} if (s > 1) {s = 0; j = 0; i = 12;}
        break;  

      case 12: w--;
               digitalWrite(l[w], HIGH);  delay(200); digitalWrite(r[w], HIGH); delay(200);
               if (w == 0) {for (byte a = 0; a < 7; a++) {digitalWrite(l[a], LOW); digitalWrite(r[a], LOW); delay(200); s++; w = 7;}}
               if (s > 20) {i = 13; s = 0; w = 7;}
        break;

      case 13: for (byte a = 0; a < 7; a++) {digitalWrite(l[a], HIGH); delay(80); digitalWrite(l[a], LOW);}
               for (byte a = 0; a < 7; a++) {digitalWrite(r[a], HIGH); delay(80); digitalWrite(r[a], LOW);}
               for (byte a = 0; a < 7; a++) {digitalWrite(r[6-a], HIGH); delay(80); digitalWrite(r[6-a], LOW);}
               for (byte a = 0; a < 7; a++) {digitalWrite(l[6-a], HIGH); delay(80); digitalWrite(l[6-a], LOW);} 
               j++; if (j > 10) {s++; j = 0;} if (s > 2) {s = 0; j = 0; i = 14;}
        break;

      case 14: for (byte a = 0; a < 7; a++) {digitalWrite(r[6-a], HIGH); digitalWrite(l[a], HIGH); delay(100);}
               delay(200);
               for (byte a = 0; a < 7; a++) {digitalWrite(r[6-a], LOW); digitalWrite(l[a], LOW); delay(100);}
               delay(200);
               j++; if (j > 15) {s++; j = 0;} if (s > 2) {s = 0; j = 0; i = 15;}
        break;

      case 15: for (byte a = 0; a < 9; a++) {digitalWrite(r[a], HIGH); digitalWrite(l[a], HIGH);  digitalWrite(r[a - 3], HIGH); digitalWrite(l[a - 3], HIGH);  
               delay(120); digitalWrite(r[a], LOW); digitalWrite(l[a], LOW); digitalWrite(r[a - 3], LOW); digitalWrite(l[a - 3], LOW);  } 
              j++; if (j > 150) {s++; j = 0;} if (s > 2) {s = 0; j = 0; i = 16;}
        break;

      case 16: for (byte a = 0; a < 7; a++) {digitalWrite(r[a], HIGH); digitalWrite(l[a], HIGH); digitalWrite(r[6-a], HIGH); digitalWrite(l[6-a], HIGH);   delay(200); }
               for (byte a = 0; a < 7; a++) {digitalWrite(r[a], LOW); digitalWrite(l[a], LOW); digitalWrite(r[6-a], LOW); digitalWrite(l[6-a], LOW);   delay(100); }
               j++; if (j > 150) {s++; j = 0;} if (s > 2) {s = 0; j = 0; i = 17;}

        break;
      
      
      
      case 17:

        i = 0;

        break;
    }


  
}

 

svetly
svetly аватар
Offline
Зарегистрирован: 23.12.2016

а где ардуино(?