[arduino] Switch control the light
Press the switch button then the light will turn on.
const int ledPin=13;
const int inputPin=2;
void setup()
{
pinMode(ledPin,OUTPUT);
pinMode(inputPin,INPUT);
digitalWrite(inputPin,HIGH);
}
void loop()
{
int val = digitalRead(inputPin);
if ( val == LOW )
{
digitalWrite(ledPin,HIGH);
}
else
{
digitalWrite(ledPin,LOW);
}
}
0 意見:
張貼留言