int RED = 9;
int GREEN = 10;
int BLUE = 11;
void setup() {
pinMode(RED,OUTPUT);
pinMode(GREEN,OUTPUT);
pinMode(BLUE,OUTPUT);
Serial.begin(9600);
}
void loop() {
if(Serial.available()>0){
char ch = Serial.read();
Serial.println(ch);
if(ch == 'a'){
digitalWrite(RED,HIGH);
digitalWrite(GREEN,LOW);
digitalWrite(BLUE,LOW);
}
else if(ch == 'b'){
digitalWrite(RED,LOW);
digitalWrite(GREEN,HIGH);
digitalWrite(BLUE,LOW);
}
else if(ch == 'c'){
digitalWrite(RED,LOW);
digitalWrite(GREEN,LOW);
digitalWrite(BLUE,HIGH);
}
else if(ch == 'd'){
digitalWrite(RED,HIGH);
digitalWrite(GREEN,LOW);
digitalWrite(BLUE,HIGH);
}
else if(ch == 'e'){
digitalWrite(RED,HIGH);
digitalWrite(GREEN,HIGH);
digitalWrite(BLUE,HIGH);
}
else if(ch == 'f'){
digitalWrite(RED,HIGH);
digitalWrite(GREEN,HIGH);
digitalWrite(BLUE,LOW);
}
}
}
Aarduino控制三色灯代码
最新推荐文章于 2024-05-02 23:06:58 发布
关键词由CSDN通过智能技术生成