|
這是按一次開關led 開 ,在按一次為關
可是問題來了~
我想要pin2~pin12 共11顆pin按鍵 想要控制同一顆led
我要如何宣告跟定義呢?
程式碼如下===========================
int LEDpin = 13; // LED on pin 13
int switchPin = 12; //點動開關 PIN12, PIN12接電阻至負極,正極5v給電壓至PIN12
boolean running = false; //設定為虛假
void setup()
{
Serial.begin(9600);
pinMode(LEDpin, OUTPUT);
pinMode(switchPin, INPUT);
digitalWrite(switchPin, LOW);
digitalWrite(LEDpin, LOW);
}
void loop()
{
if (digitalRead(switchPin) == HIGH)
{
delay(500);
running = !running;
digitalWrite(LEDpin, running) ;
delay(500);
Serial.print(switchPin);
Serial.print(LEDpin);
}
}
================================ |
|