1. Home
  2. /
  3. IOT 物聯網
  4. /
  5. Arduino
  6. /
  7. [ Arduino ] –...

[ Arduino ] – Switch LED 幫 LED 燈加上開關

評等結果
點擊便能為這篇文章進行評等!
[評等總次數: 0,平均評等: 0]

[java]
const int buttonPin = 2; // the number of the pushbutton pin
const int ledPin = 13; // the number of the LED pin
static int ledStatus;
// variables will change:
int buttonState = 0; // variable for reading the pushbutton status
void setup() {
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
ledStatus = LOW;
}
void loop(){
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (buttonState == HIGH) {
// turn LED on:
ledStatus = ledStatus == HIGH ? LOW : HIGH;
delay(300);
digitalWrite(ledPin, ledStatus);
}
}
[/java]
參考網址
http://yehnan.blogspot.tw/2012/02/arduinoled.html

評等結果
點擊便能為這篇文章進行評等!
[評等總次數: 0,平均評等: 0]
!去下營經續永站本助幫能就下一點輕輕,話的您到助幫有章文的我果如 如果我的文章有幫助到您的話,輕輕點一下就能幫助本站永續經營下去!

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *