首页 » 业余 » Arduino » 正文

Arduino 红绿灯+风扇

发布者:站点默认
2025/01/12 浏览数(13) 分类:Arduino Arduino 红绿灯+风扇已关闭评论

绿灯风停,红灯刮风,红绿间隙黄灯。

int Red = 13;     // 红灯
int Yellow = 12;  // 黄灯
int Green = 11;   // 绿灯
int FanA = 8;     // 风扇 VINA
int FanB = 9;     // 风扇 VINB

void setup() {
  pinMode(FanA, OUTPUT);
  pinMode(FanB, OUTPUT);
  pinMode(Red, OUTPUT);
  pinMode(Yellow, OUTPUT);
  pinMode(Green, OUTPUT);
}

void loop() {
  // 绿灯亮
  digitalWrite(Green, HIGH);
  delay(3000);

  // 关绿亮黄
  digitalWrite(Green, LOW);
  digitalWrite(Yellow, HIGH);
  delay(1000);

  // 关黄亮红开风扇
  digitalWrite(Yellow, LOW);
  digitalWrite(Red, HIGH);
  digitalWrite(FanA, LOW);
  digitalWrite(FanB, HIGH);
  delay(6000);

  // 停风扇停红亮黄
  digitalWrite(FanA, LOW);
  digitalWrite(FanB, LOW);
  digitalWrite(Yellow, HIGH);
  digitalWrite(Red, LOW);
  delay(2000);

  // 停黄
  digitalWrite(Yellow, LOW);
}
点击返回顶部
  1. 留言
  2. 联系方式