The components we will be using for this are
1) Arduino board
2) a Breadboard
3) some wires
4) A Tact Switch
5) A LED
6) Resistors - 220 Ohm, and 10 Kilo Ohm
Let us start with the wiring.
I have a png image of the circuit diagram I have created on Tinkercad. It is a full size image. This image is available on this link for you to download.
Let us place the Tact switch on the breadboard.
You can place it in only one way, over the ridge along the center of the breadboard.
Now I will connect one end the 10 Kilo ohms resistor to one end of the switch and other end of the resistor to the negative of the breadboard.
Place the LED on the breadboard.
Connect the 220 ohms resistor between negative/smaller pin/cathode of the LED and the negative line of the breadboard.
Now I will connect a black wire to a Ground pin on Arduino, and a Red wire to 5V pin on Arduino.
Connect the other end of black wire to the negative of the breadboard, and the other end of the Red wire to the positive of the breadboard.
We have connected one end of the switch to ground through the resistor.
Now lconnect other end of the switch to the positive of the breadboard
Now I will connect a yellow wire to the pin of the switch that is connected with the resistor.
You can connect the other end of this yellow wire to any digital i/o port on Arduino. I am connecting it to port no 10.
Although we don't need the PWM functionality here.
I am connecting a white wire to the longer pin of the LED/ the Anode, and other end of the wire to the Pin no 11 on Arduino.
Now let us power this circuit.
I have already uploaded the program in it.
The LED turns on immediately.
It normally stays on, until we press the switch and as long as we keep it pressed.
That is how the Tact switches function
Now let us make some changes in the circuit to make the LED stay normally off.
This image is available on this link for you to download.
The only change that we will make here is to move the resistor connected between the switch and the ground to switch and the positive line instead and then ground the other pin of the switch. That's all.
When we power this circuit, the LED is off, and it remains off until we press the button, and as long as we keep the button pressed, it stays on.
So these are the two circuits that we can run with a single program from the xod.
Now let us see how to create this program in xod.
open the xod program. Press i. search for "button", select the button, drag it on the screen elsewhere.
now search for and select "led"
position the LED box below the button box.
Select "button", type 10 in front of the port value
Select "LED", type 11 in front of the port value
Now create a link between PRS from the button and LUM of the led.
That's it. That is all there is in this program. upload this program on Arduino and test it with the two circuits we just built.