接線圖
X1 Arduino Uno R3X1 單色LED
X1 220~10k Ω 電阻
X2 按鈕
LED燈需要接上電阻 避免電流過大燒壞
左邊按鈕按下 LED 亮燈
右邊按鈕按下 LED 暗燈
Arduino IDE code
int ledPin = 5;
int buttonApin = 9;
int buttonBpin = 8;
byte leds = 0;
void setup()
{
pinMode(ledPin, OUTPUT);
pinMode(buttonApin, INPUT_PULLUP);
pinMode(buttonBpin, INPUT_PULLUP);
}
void loop()
{
if (digitalRead(buttonApin) == LOW)
{
digitalWrite(ledPin, HIGH);
}
if (digitalRead(buttonBpin) == LOW)
{
digitalWrite(ledPin, LOW);
}
}
沒有留言:
張貼留言