Read Button Press Code
int buttonState = 0;
int buttonPin = 8;
int LEDpin = 7;
void setup() {
Serial.begin(9600);
}
void loop() {
pinMode(buttonPin,INPUT);
pinMode(LEDpin, OUTPUT);
buttonState = digitalRead(buttonPin);
if(buttonState==0){
Serial.println("Button is pressed");
digitalWrite(LEDpin, LOW);
}
else if(buttonState >0){
digitalWrite(LEDpin, HIGH);
Serial.println("Button is not pressed");
}
}
int buttonState = 0;
int buttonPin = 8;
int LEDpin = 7;
void setup() {
Serial.begin(9600);
}
void loop() {
pinMode(buttonPin,INPUT);
pinMode(LEDpin, OUTPUT);
buttonState = digitalRead(buttonPin);
if(buttonState==0){
Serial.println("Button is pressed");
digitalWrite(LEDpin, LOW);
}
else if(buttonState >0){
digitalWrite(LEDpin, HIGH);
Serial.println("Button is not pressed");
}
}
Circuit
No comments:
Post a Comment