跑马灯程序

 1 void setup() {
 2   // put your setup code here, to run once:
 3   int i;
 4   for(i = 7;i <= 12;i++){
 5     pinMode(i,OUTPUT);
 6   }
 7 
 8 }
 9 int now=  7;
10 int mode = 0;
11 void loop() {
12   // put your main code here, to run repeatedly
13   if(mode == 0){
14   int i;
15   for(i = 7;i <= 12;i++){
16     digitalWrite(i,LOW);
17   }
18   digitalWrite(now,HIGH);
19   delay(200);
20   now++;
21   if(now > 12){now = 12;mode = 1;}
22   
23   }
24   else if (mode == 1)
25   {
26     int i;
27   for(i = 7;i <= 12;i++){
28     digitalWrite(i,LOW);
29   }
30   digitalWrite(now,HIGH);
31   delay(200);
32   now--;
33   if(now < 7){now = 7;mode = 0;}
34   
35   }
36 
37 }
View Code

6个灯采用共阴接法,LED接330欧电阻,然后接地,没有接5V

转载于:https://www.cnblogs.com/lwy-kitty/p/4896238.html

你可能感兴趣的:(跑马灯程序)