电子说
课程目标
相关知识
电路搭建
程序编写
/* 项目名称:RGB红绿灯
* 项目时间:2022.02.21
* 项目作者:MRX
*/
int led_R = 9;
int led_G = 10;
int led_B = 11;
void red(){
analogWrite(led_R,255);
analogWrite(led_G,0);
analogWrite(11,0);
}
void green(){
analogWrite(led_R,0);
analogWrite(led_G,255);
analogWrite(led_B,0);
}
void yellow() {
analogWrite(led_R,255);
analogWrite(led_G,255);
analogWrite(led_B,0);
}
void closed() {
analogWrite(led_R,0);
analogWrite(led_G,0);
analogWrite(led_B,0);
}
void setup() {
pinMode(led_R,OUTPUT);
pinMode(led_G,OUTPUT);
pinMode(led_B,OUTPUT);
}
void loop() {
red();
delay(7000);
green();
delay(7000);
for (int i = 0; i <= 2; i = i + (1)) {
yellow();
delay(500);
closed();
delay(500);
}
}
全部0条评论
快来发表一下你的评论吧 !