Arduino/elegoo-kit-lessons/Lesson 8 Ball Switch/Ball_Switch/Ball_Switch.ino

27 lines
538 B
Arduino
Raw Permalink Normal View History

2022-02-20 21:05:40 +00:00
//www.elegoo.com
//2016.12.08
/*****************************************/
const int ledPin = 13;//the led attach to
void setup()
{
pinMode(ledPin,OUTPUT);//initialize the ledPin as an output
pinMode(2,INPUT);
digitalWrite(2, HIGH);
}
/******************************************/
void loop()
{
int digitalVal = digitalRead(2);
if(HIGH == digitalVal)
{
digitalWrite(ledPin,LOW);//turn the led off
}
else
{
digitalWrite(ledPin,HIGH);//turn the led on
}
}
/**********************************************/