- Arduino UNO
- 按鈕
- LED
- 10KΩ電阻
按下按鈕時,點亮腳位13的LED燈
int pushButton = 2 ;
int ledPin = 13 ;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600) ;
pinMode(pushButton,INPUT) ;
pinMode(ledPin,OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
boolean buttonState = digitalRead(pushButton) ;
if( buttonState) {
digitalWrite(ledPin,HIGH) ;
}else{
digitalWrite(ledPin,LOW);
}
delay(1) ;
}