1.实现13号端口的闪烁:
原理图:
代码:
int led = 13;
void setup() {
pinMode(led,OUTPUT);
}
void loop() {
digitalWrite(led,HIGH);
delay(100);
digitalWrite(led,LOW);
delay(100);
}
2.跑马灯效果:
原理图:
代码:
int timer = 100;
void setup() {
for(int thisPin = 2 ;thisPin<8;thisPin++){
pinMode(thisPin,OUTPUT);
}
}
void loop() {
for(int thisPin = 2 ;thisPin<8;thisPin++){
digitalWrite(thisPin,HIGH);
delay(timer);
digitalWrite(thisPin,LOW);
}
for(int thisPin = 7 ;thisPin<2;thisPin--){
digitalWrite(thisPin,HIGH);
delay(timer);
digitalWrite(thisPin,LOW);
}
}
实验现象: