Arduino/elegoo-kit-lessons/Lesson 8 Ball Switch/Ball_Switch/Ball_Switch.ino
2022-02-20 16:18:02 -05:00

27 lines
538 B
C++
Executable File

//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
}
}
/**********************************************/