int redPin = 9;
int greenPin = 10;
int yellowPin = 8;
char ab;
void setup() {
Serial.begin(9600);
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(yellowPin, OUTPUT);
}
void loop() {
if (Serial.available()>0)
{
ab=Serial.read();
Serial.println(ab);
if (ab=='r'||ab=='R'){
redOne();
}
else if (ab=='g'||ab=='G'){
greenOne();
}
else if (ab=='y'||ab=='Y'){
yellowOne();
}
else { Serial.println("input error!");
}
}
}
void redOne(){
digitalWrite(redPin,HIGH);
delay(10000);
digitalWrite(redPin,LOW);
}
void greenOne(){
digitalWrite(greenPin,HIGH);
delay(10000);
digitalWrite(greenPin,LOW);
}
void yellowOne(){
digitalWrite(yellowPin,HIGH);
delay(10000);
digitalWrite(yellowPin,LOW);
}
int greenPin = 10;
int yellowPin = 8;
char ab;
void setup() {
Serial.begin(9600);
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(yellowPin, OUTPUT);
}
void loop() {
if (Serial.available()>0)
{
ab=Serial.read();
Serial.println(ab);
if (ab=='r'||ab=='R'){
redOne();
}
else if (ab=='g'||ab=='G'){
greenOne();
}
else if (ab=='y'||ab=='Y'){
yellowOne();
}
else { Serial.println("input error!");
}
}
}
void redOne(){
digitalWrite(redPin,HIGH);
delay(10000);
digitalWrite(redPin,LOW);
}
void greenOne(){
digitalWrite(greenPin,HIGH);
delay(10000);
digitalWrite(greenPin,LOW);
}
void yellowOne(){
digitalWrite(yellowPin,HIGH);
delay(10000);
digitalWrite(yellowPin,LOW);
}