Skip to content

Instantly share code, notes, and snippets.

@arduinothai
Last active July 31, 2019 07:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arduinothai/6dc301a6e763fa98471aa37ec39b633b to your computer and use it in GitHub Desktop.
Save arduinothai/6dc301a6e763fa98471aa37ec39b633b to your computer and use it in GitHub Desktop.
const int ledPin = 13;// the led attach to pin13
int digitalPin = 2; // attach to pin 2
boolean digitalValue=0;// variable to store the value coming from pin2
void setup()
{
pinMode(digitalPin,INPUT);//set the state of pin2 as INPUT
pinMode(ledPin,OUTPUT);//set the state of pin13 as OUTPUT
Serial.begin(9600); // initialize serial communications at 9600 bps
}
void loop()
{
digitalValue=digitalRead(digitalPin); //read the value of pin2
Serial.print("Digital Value "); // print label to serial monitor
Serial.println(digitalValue);
if( digitalValue==HIGH )
{
digitalWrite(ledPin,LOW);//turn off the led
}
else
{
digitalWrite(ledPin,HIGH);//turn on the led
}
delay(1000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment