[vc_row][vc_column][vc_column_text]Until now, we have been focused on learning outputs.Now we will begin to understand the input.In this circuit, we will learn about the most common and easiest Enter one – one button. The principle of buttons and pcDuino work together is that when the button is pressed, the voltage becomes low. pcDuino reads this information and respond accordingly. In this circuit, you will use a pull-up resistor, which is used when you do not press the button maintain a high voltage.[/vc_column_text][/vc_column][/vc_row][vc_row][vc_column width=”1/1″][vc_tour][vc_tab title=”Parts list” tab_id=”1393910784-1-13″][vc_column_text]1 two button
2 one red LED
3.two 10K resistors
4.one 330 ohm resistor
5 seven wires[/vc_column_text][/vc_tab][vc_tab title=”Vulcan logic use” tab_id=”1393910784-2-56″][vc_column_text]The pcduino can make complex decisions based on input.For example , pcduino can do a thermostat in a cold environment to put the heater turned on, if too hot,it can put the fan on , if your plants are too dry and watering , etc.
In order to make such a decision , Arduino environment provides a series of logical operations , so that you can create complex “if” condition , they include :
== Equivalence If A and B are the same,and A==B is true.
!= Difference If A and B are not the same then A! = B is true.
&& And If A and B are true then A && B is true.
|| OR If A or B or both are true, then A | | B is true.
! NO If A is false , then ! A is true. If A is true, then ! A is false.
You can combine these functions to create a complex if () called .
For example:
If(mode ==heat)&&((temperature <threshold)||(override==true))
{
digitalWrite(HEATER,HIGH):
}
If you are in the heating mode , and the temperature is low , or if you open a manual adjustment , then the sleep function to start the heater . Using these logical operators , you can program pcDuino to make some very wise decisions and control the world around you !
[/vc_column_text][/vc_tab][vc_tab title=”Key code” tab_id=”1393911544321-2-9″][vc_column_text]pinMode(button2Pin, INPUT);
The digital interface can be used both as input and as output. Before you do any decision , you need to tell pcDuino which direction you intend to go.
button1State = digitalRead(button1Pin);
You use digitalRead () function to read a digital input. If the interface is 5 volts, then it will return to “HIGH”, if the interface is 0 volts , return “LOW”.
if (button1State == LOW)
Because we received the keys to GND, if the button is pressed, then it will read “LOW”. Here we use the “equivalent” operator “==” view whether the button is pressed.
ont-family:’Times New Roman’; ” >[/vc_column_text][/vc_tab][vc_tab title=”Results” tab_id=”1393911547514-3-2″][vc_column_text]You will see:
When you press any key ,LED will light up .when you press two buttons simultaneously , LED lights will be off. (See the code to find out the reason). If the circuit is not working, make sure that your circuit is properly connected, compile and upload the code to the board, or refer to the following troubleshooting tips.
Troubleshooting:
Lamp is not on
Because the keys are square, so it is easy to insert the wrong position. Please try to rotate 90 degrees to see if it is working.
A little boring
Do not worry, these circuits are more easily to try to learn the depth of each components were decomposed, once you put them all together and we have a lot of fun.
Real-world applications:
Here we use the keys is the same as the buttons on a video game controller[/vc_column_text][/vc_tab][/vc_tour][/vc_column][/vc_row]
Leave a Reply
You must be logged in to post a comment.