Last active
July 31, 2019 07:22
-
-
Save arduinothai/6dc301a6e763fa98471aa37ec39b633b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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