![]() Int flag = 0 //Declared variable flag to store switch state Int btn_state = 0 //Declared variable to store state (Low by default) Let’s take a look at the code: #define LED 10 //Declared pin 10 as LED Flags are variables that save the state of a pin (High/low or integers). To use the pushbutton as a toggle switch we need to remember the switch state. For that we will have to make some changes to the code. Let’s say we want to toggle LED on and off using the same switch. This works very well but sometimes we need a different arrangement. The circuit is completed when button is pressed and pins 1,3 and 2,4 are shorted. The pins in vertical line are connected together. Usually push buttons have 4 pins marked as 1,2,3 & 4. ![]() To understand the working refer to the diagram. But before that, let’s first see how a push button works. Once you have everything we need, we can connect it all and make a circuit. Breadboard with Jumpers ( Amazon US / Amazon EU).Buying product from those links helps us run this blog without any charges on you. So without wasting any more time, lets begin.ĭisclaimer: This blog contains Amazon Affiliate links. It will be very useful for future projects. In this article I will show you how to use a Pushbutton to control the LED. We also learnt how to program the microcontroller to blink a LED. In the previous tutorial I shared a quick introduction to Arduino Uno.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |