Arduino ide 基于C++,区分大小写 。
void setup( ) {
}
只执行一次。
void loop( ) {
}
循环执行。
// 开头的是行注释。
/*
*/ 是段注释。
pinMode(13,OUTPUT); // 定义13号引脚为输出模式。
int 定义整型变量。
digitalWrite(13,HIGH); 给13号引脚高电平。低电平为LOW。
delay(1000); 延时1000ms =1s。
程序如下:
int g1=4;
int y1=5;
int r1=6;
int g2=7;
int y2=8;
int r2=9;
int g1t=10000;
int g2t=10000;
void setup() {
// put your setup code here, to run once:
pinMode(g1,OUTPUT);
pinMode(y1,OUTPUT);
pinMode(r1,OUTPUT);
pinMode(g2,OUTPUT);
pinMode(y2,OUTPUT);
pinMode(r2,OUTPUT);
}
void loop() {
// GREEN
digitalWrite(g1,HIGH);
digitalWrite(r2,HIGH);
delay(g1t);
digitalWrite(g1,LOW);
delay(200);
digitalWrite(g1,HIGH);
delay(1000);
digitalWrite(g1,LOW);
delay(200);
digitalWrite(g1,HIGH);
delay(1000);
digitalWrite(g1,LOW);
delay(200);
digitalWrite(g1,HIGH);
delay(1000);
digitalWrite(g1,LOW);
delay(200);
//YELLOW
digitalWrite(y1,HIGH);
delay(1000);
digitalWrite(y1,LOW);
delay(200);
digitalWrite(y1,HIGH);
delay(1000);
digitalWrite(y1,LOW);
delay(200);
digitalWrite(y1,HIGH);
delay(1000);
digitalWrite(y1,LOW);
digitalWrite(r2,LOW);
delay(200);
//RED
digitalWrite(r1,HIGH);
digitalWrite(g2,HIGH);
delay(g2t);
digitalWrite(g2,LOW);
delay(200);
digitalWrite(g2,HIGH);
delay(1000);
digitalWrite(g2,LOW);
delay(200);
digitalWrite(g2,HIGH);
delay(1000);
digitalWrite(g2,LOW);
delay(200);
digitalWrite(g2,HIGH);
delay(1000);
digitalWrite(g2,LOW);
delay(200);
//YELLOW
digitalWrite(y2,HIGH);
delay(1000);
digitalWrite(y2,LOW);
delay(200);
digitalWrite(y2,HIGH);
delay(1000);
digitalWrite(y2,LOW);
delay(200);
digitalWrite(y2,HIGH);
delay(1000);
digitalWrite(y2,LOW);
digitalWrite(r1,LOW);
delay(200);
}
网友评论