抢答器

当按键按下时,数字10、9、8接口可读出为高电平,这时我们使数字7、6、5口输出高电平可使小灯亮起,程序中我们判断数字10、9、8口是否为低电平,要为低电平使数字7、6、5口输出也为低电平,小灯不亮。

原理图

抢答器原理图

实物连接图

抢答器连线

程序代码

int redled = 10;
int yellowled = 9;
int greenled = 8;
int redpin = 7;
int yellowpin = 6;
int greenpin = 5;
int red;
int yellow;
int green;
void setup()
{
  pinMode(redled, OUTPUT);
  pinMode(yellowled, OUTPUT);
  pinMode(greenled, OUTPUT);
  pinMode(redpin, INPUT);
  pinMode(yellowpin, INPUT);
  pinMode(greenpin, INPUT);
}
void loop()
{
  red = digitalRead(redpin);
  if (red == LOW)
  {
    digitalWrite(redled, LOW);
  }
  else
  {
    digitalWrite(redled, HIGH);
  }
  yellow = digitalRead(yellowpin);  
  if (yellow == LOW)
  {
    digitalWrite(yellowled, LOW);
  }
  else
  {
    digitalWrite(yellowled, HIGH);
  }
  green = digitalRead(greenpin);
  if (green == LOW)
  {
    digitalWrite(greenled, LOW);
  }
  else
  {
    digitalWrite(greenled, HIGH);
  }
}
文件下载(已下载 2 次)

发布时间:2019/7/6 21:13:11  阅读次数:849

2006 - 2022,推荐分辨率1024*768以上,推荐浏览器IE9.0及以上,截止2021年12月5日的访问次数:1872万9823沪ICP备18037240号-1

沪公网安备 31011002002865号