编号: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
暂无评论