●课程视频

●课程课件

第5课-抢答器

●课程程序

int yellowLed = 9;
int greenLed = 7;

int yellowButton = 11;
int greenButton = 5;

int yellowVal;
int greenVal;

void setup()
{
  pinMode(yellowLed, OUTPUT);
  pinMode(greenLed, OUTPUT);

  pinMode(yellowButton, INPUT);
  pinMode(greenButton, INPUT);
}
void loop()
{
  yellowVal = digitalRead(yellowButton);
  greenVal = digitalRead(greenButton);

  if (greenVal == LOW)
  {
    digitalWrite(greenLed, LOW);
  }
  else
  {
    digitalWrite(greenLed, HIGH);
    delay(5000);
  }
  
  if (yellowVal == LOW)
  {
    digitalWrite(yellowLed, LOW);
  }
  else
  {
    digitalWrite(yellowLed, HIGH);
    delay(5000);
  }
}