code formatting whe...
 
Notifications
Clear all

code formatting when posting  

  RSS

BullwinkleII
(@bullwinkleii)
Active Member
Joined: 3 months ago
Posts: 12
2020-02-28 1:34 pm  

 

String answer;
String msg = "Do you want me to light the red, yellow, or blue LED?";

#define red 22
#define blue 24
#define green 26

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  pinMode(red, OUTPUT);
  pinMode(blue, OUTPUT);
  pinMode(green, OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  Serial.println();
  Serial.println(msg);
  while (Serial.available() == 0) {
    //wait
  }

  answer = Serial.readString();

  if (answer == "red") {
    digitalWrite (red, HIGH);
    digitalWrite (blue, LOW);
    digitalWrite (green, LOW);
  }
  if (answer == "blue") {
    digitalWrite (blue, HIGH);
    digitalWrite (red, LOW);
    digitalWrite (green, LOW);
  }
  if (answer == "green") {
    digitalWrite (green, HIGH);
    digitalWrite (red, LOW);
    digitalWrite (blue, LOW);

  }

}

My skills include being able to move slowly forward in time, and if I really concentrate, I can sometimes tell what I'm thinking.


Quote