[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
[ Arduino ] – Switch LED 幫 LED 燈加上開關
評等結果
點擊便能為這篇文章進行評等!
[評等總次數: 0,平均評等: 0]
評等結果
點擊便能為這篇文章進行評等!
[評等總次數: 0,平均評等: 0]