Arduino Nano

Arduino basic Tutorial

Blynk iot Tutorial

Visit all the Links

ArduinoTutorial by Manmohan Pal

How to Read INPUT from SWITCH


How to Read INPUT from SWITCH




How to Read INPUT from SWITCH


COPY AND PAST THE CODE IN ARDUINO IDE SKETCH

------------------------------------------------------------------------------------
                                                     CODE
------------------------------------------------------------------------------------


int switch1=2;
int LED1=13;
int buttonstate=0;

void setup() {
  // put your setup code here, to run once:
pinMode(switch1,INPUT);
pinMode(LED1,OUTPUT);
}

void loop() {
   // put your main code here, to run repeatedly:
  buttonstate=(digitalRead(switch1);

  if (buttonstate==HIGH)
  {
    digitalWrite(LED1,HIGH);
  }

else
  {
    digitalWrite(LED1,LOW);
  }
  // put your main code here, to run repeatedly:
}
----------------------------------------------------------------------------------








1 comment: