彰化一整天的論壇

 找回密碼
 立即註冊
查看: 530|回復: 0

使用digitalRead()

[複製鏈接]
發表於 2016-10-6 20:47:35 | 顯示全部樓層 |閱讀模式
  1. /*
  2.   Blink
  3.   Turns on an LED on for one second, then off for one second, repeatedly.

  4.   This example code is in the public domain.
  5. */

  6. // Pin 13 has an LED connected on most Arduino boards.
  7. // give it a name:
  8. int ledPin = 13;
  9. int inPin=7;
  10. int val = 0;
  11. // the setup routine runs once when you press reset:
  12. void setup() {               
  13.   // initialize the digital pin as an output.
  14.   pinMode(ledPin, OUTPUT);     
  15.   pinMode(inPin, INPUT);
  16. }

  17. // the loop routine runs over and over again forever:
  18. void loop() {
  19.   val=digitalRead(inPin);
  20.   if(val==HIGH){
  21.     digitalWrite(ledPin, LOW);
  22.   }else{
  23.     digitalWrite(ledPin, HIGH);
  24.   }
  25. }
複製代碼


回復

使用道具 舉報

您需要登錄後才可以回帖 登錄 | 立即註冊

本版積分規則

Archiver|手機版|小黑屋|彰化一整天的論壇(Excel,Office)  |网站地图

GMT+8, 2019-8-20 04:25 , Processed in 0.132471 second(s), 21 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回復 返回頂部 返回列表