抢答器
当按键按下时,数字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); } }文件下载(已下载 3 次)
发布时间:2019/7/6 下午9:13:11 阅读次数:2474