Arduino入门篇:第五章代码及练习答案

编号:button_RYG

<br> const int RED = 8;        //红色<br> const int YELLOW = 9;     //黄色<br> const int GREEN = 10;     //绿色<br> const int BUTTON = 11;    //按键连接管脚      </p> 
<p><br> void setup() {<!-- --><br>   // put your setup code here, to run once:<br>   pinMode(RED, OUTPUT);<br>   pinMode(YELLOW, OUTPUT);<br>   pinMode(GREEN, OUTPUT);<br>   pinMode(BUTTON, INPUT_PULLUP);<br>   digitalWrite(RED, LOW);<br>   digitalWrite(YELLOW, LOW);<br>   digitalWrite(GREEN, LOW);<br> }</p> 
<p>void loop() {<!-- --><br>   // put your main code here, to run repeatedly:<br>   if(digitalRead(BUTTON) == LOW){       //低电平表示按键被按下<br>       digitalWrite(RED, HIGH);<br>       digitalWrite(YELLOW, LOW);<br>       digitalWrite(GREEN, LOW);<br>       delay(5000);<br>       digitalWrite(YELLOW, HIGH);<br>       delay(5000);<br>   }else {                   //按键没有被按下<br>       digitalWrite(RED, LOW);<br>       digitalWrite(YELLOW, LOW);<br>       digitalWrite(GREEN, HIGH);<br>   }    <br> }<br> 

=========================================================================

编号:button_RYG_2

<br> const int RED = 8;        //红色<br> const int YELLOW = 9;     //黄色<br> const int GREEN = 10;     //绿色<br> const int BUTTON = 11;    //按键连接管脚      </p> 
<p><br> void setup() {<!-- --><br>   // put your setup code here, to run once:<br>   pinMode(RED, OUTPUT);<br>   pinMode(YELLOW, OUTPUT);<br>   pinMode(GREEN, OUTPUT);<br>   pinMode(BUTTON, INPUT_PULLUP);<br>   digitalWrite(RED, LOW);<br>   digitalWrite(YELLOW, LOW);<br>   digitalWrite(GREEN, LOW);<br> }</p> 
<p>void loop() {<!-- --><br>   // put your main code here, to run repeatedly:<br>   if(digitalRead(BUTTON) == LOW){       //低电平表示按键被按下<br>       digitalWrite(YELLOW, HIGH);<br>       delay(5000);<br>       digitalWrite(RED, HIGH);<br>       digitalWrite(YELLOW, LOW);<br>       digitalWrite(GREEN, LOW);<br>       delay(5000);<br>       digitalWrite(YELLOW, HIGH);<br>       delay(5000);<br>   }else {                   //按键没有被按下<br>       digitalWrite(RED, LOW);<br>       digitalWrite(YELLOW, LOW);<br>       digitalWrite(GREEN, HIGH);<br>   }    <br> }<br> 

版权声明:本文为CSDN博主「金刚熊猫」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/xyysun/article/details/122271206

编号:button_RYG

<br> const int RED = 8;        //红色<br> const int YELLOW = 9;     //黄色<br> const int GREEN = 10;     //绿色<br> const int BUTTON = 11;    //按键连接管脚      </p> 
<p><br> void setup() {<!-- --><br>   // put your setup code here, to run once:<br>   pinMode(RED, OUTPUT);<br>   pinMode(YELLOW, OUTPUT);<br>   pinMode(GREEN, OUTPUT);<br>   pinMode(BUTTON, INPUT_PULLUP);<br>   digitalWrite(RED, LOW);<br>   digitalWrite(YELLOW, LOW);<br>   digitalWrite(GREEN, LOW);<br> }</p> 
<p>void loop() {<!-- --><br>   // put your main code here, to run repeatedly:<br>   if(digitalRead(BUTTON) == LOW){       //低电平表示按键被按下<br>       digitalWrite(RED, HIGH);<br>       digitalWrite(YELLOW, LOW);<br>       digitalWrite(GREEN, LOW);<br>       delay(5000);<br>       digitalWrite(YELLOW, HIGH);<br>       delay(5000);<br>   }else {                   //按键没有被按下<br>       digitalWrite(RED, LOW);<br>       digitalWrite(YELLOW, LOW);<br>       digitalWrite(GREEN, HIGH);<br>   }    <br> }<br> 

=========================================================================

编号:button_RYG_2

<br> const int RED = 8;        //红色<br> const int YELLOW = 9;     //黄色<br> const int GREEN = 10;     //绿色<br> const int BUTTON = 11;    //按键连接管脚      </p> 
<p><br> void setup() {<!-- --><br>   // put your setup code here, to run once:<br>   pinMode(RED, OUTPUT);<br>   pinMode(YELLOW, OUTPUT);<br>   pinMode(GREEN, OUTPUT);<br>   pinMode(BUTTON, INPUT_PULLUP);<br>   digitalWrite(RED, LOW);<br>   digitalWrite(YELLOW, LOW);<br>   digitalWrite(GREEN, LOW);<br> }</p> 
<p>void loop() {<!-- --><br>   // put your main code here, to run repeatedly:<br>   if(digitalRead(BUTTON) == LOW){       //低电平表示按键被按下<br>       digitalWrite(YELLOW, HIGH);<br>       delay(5000);<br>       digitalWrite(RED, HIGH);<br>       digitalWrite(YELLOW, LOW);<br>       digitalWrite(GREEN, LOW);<br>       delay(5000);<br>       digitalWrite(YELLOW, HIGH);<br>       delay(5000);<br>   }else {                   //按键没有被按下<br>       digitalWrite(RED, LOW);<br>       digitalWrite(YELLOW, LOW);<br>       digitalWrite(GREEN, HIGH);<br>   }    <br> }<br> 

版权声明:本文为CSDN博主「金刚熊猫」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/xyysun/article/details/122271206

生成海报
点赞 0

金刚熊猫

我还没有学会写个人说明!

暂无评论

发表评论

相关推荐

基于Arduino的显示测量环境数据设计

题目: 基于Arduino的显示测量环境数据设计 目录 基于Arduino的显示测量环境数据设计... 3 第一章 课题任务... 4 1.1课题任务... 4 1.2任务分工... 4 1.3设计条件... 4 第

2021全国电设(F题)灰度传感器——循迹红线

基于灰度传感器的循迹(红色循迹) 通过参加全国电子设计大赛F题总结出识别红色线路的循迹方法——灰度传感器 灰度传感器的工作原理 灰度传感器利用不同颜色的检测面对光的反射程度不同,光敏电阻对不同检测面返