PinMode(redLED4, OUTPUT) //Red LED as output PinMode(greenLED3, OUTPUT) //Green LED as output PinMode(yellowLED2, OUTPUT) //Yellow LED as output PinMode(blueLED1, OUTPUT) //Blue LED as output If condition is true, digitalWrite() make digital output pins active high and otherwise these output pins remains active low.Next, we shall move onto the coding portion. Inside the loop(), first we check the state of pin zero using digitalRead() function and save the state of pin in “buttonstate” variable.Īfter that if condition is used to check the state “buttonstate” variable. void setup()Īs you know that in Arduino sketch, everything that executes again and again place inside the loop function. Similarly, we declare digital pin zero as a input pin. Inside the setup function, we configure digital pin 1 and 2 as output pins using pinMode() routine. Int buttonStatus // Variable declare to store status of digitalWrite() It will eliminate the need for an external resistor. In the later section of this tutorial, we will see how to use the push button by using the internal pull-up resistor of Arduino. It will make the state of digital input logic low as soon as we release the push button, otherwise, a floating state will appear on the digital input zero.Īrduino also has an internal pull-down resistor. Note: 10k Ohm resistor with push-button is used as a pull-down resistor. When the push button is not pressed, a logic low is used as input for pin 0 and when the push button is pressed, logic high is used as an input of pin 0. Push-button one side is connected with 5-volt source and the other side is connected with ground through 10k ohm resistor. Two resistors are connected in series with both LEDS as a current limiting resistor. Both LEDs glow and when a push button is unpressed, LEDs remains turn off. Push button is basically used to control two LEDs or to turn on/off two LEDs.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
December 2022
Categories |