The world seems bound Arduino, the first program we do is the blinking LED, and is well because it illustrates some interesting ideas about its possibilities:
-The ability to interact with the outside world. Something quite unusual for those who are accustomed to traditional computing, where computing power has grown dramatically, but it is still impossible (or nearly so), influence the outside world.
-The Simplicity of the work environment. In contrast to a traditional system editor / compiler / linker.
Arduino can interact in different ways with the world around him, we start by digital pins that can be used as:
-Entrance fees: To read digital information from the outside world.
-Outflows: To activate a signal to the outside world.
Arduino has 14 pins that can be used in this way, numbered 0 to 13.
Arduino will ask you activate your pin as digital output 13 and then will light and will quench this signal which will cause the LED is connected serial turns on or off the pace we mark.
To tell the system we want to use the digital output pin 13 as we use the command:
pinMode (13, OUTPUT);
The first parameter indicates the pin to use and "OUTPUT" is for use as an output, and the value "INPUT" could also be used to indicate that we will read this pin.
These definitions will be made only once at the beginning, in the setup (function). Ours will, with a single statement declaring that we will use pin 13 as a digital output:
void setup ()
{
// Initialize the digital pin as an output
pinMode (13, OUTPUT);
}
It is important to note that despite being a single instruction, we have defined the block this function by opening and closing keys.
Note that the statement ends in ";". C ++ requires instructions end with a semicolon to delimit the order. If omitted fail.
To turn the LED use the command:
digitalWrite (13, HIGH);
And another similar instruction ordering it to turn it off:
digitalWrite (13, LOW);
13 shows the pin to use and HIGH, LOW indicate the value we want to put on that output, which correspond to Arduino 5V and 0V for LOW HIGH.
If the loop function () we write these two followed instructions, Arduino change these values so fast that not perceive changes, so we need to stop him a bit so we can perceive the change.
To make this delay of, say, a second, we use:
delay (1000); // Delay (n) "freezes" Arduino n milliseconds
Therefore to schedule a light that turns on and off, we would have to generate a sequence of commands (as in a recipe and kitchen) to do:
-Inform Arduino that we will use the pin13 to write values (in Setup).
-Turn on the LED: Put high (5V) on said pin.
-Wait a second.
-Off the LED: Set low (0V) on said pin.
-Return to wait a second.
If we omitted this second delay, extinguish the light and would start meeting the order to relight. Not appreciate that he had off. (I hope not believe me. Check it out for).
UNO Arduino processor is very slow from the electronic point of view, but is capable of switching the light (switch from on to off and back on again) about 15,000 times per second.
void setup()
{
pinMode( 13 , OUTPUT); // We use the output pin 13
}
void loop()
{
digitalWrite(13 , HIGH); // Turn on the LED
delay(1000); // Wait one second
digitalWrite(13 , LOW); // Turn off the LED
delay(1000); // Wait another second
}
Note the bleeding lines to highlight code blocks. This is considered good practice and I would highly recommend, because much easier to understand the program.
When Eurpoean (and creadme, you are going to go wrong) bleeding help, and much, to view the program.
There are only two types of programmers. Those who make mistakes and to be wrong.
We only need already, check for errors and to do this click the icon in yellow.
If all goes well, (if there are no errors in red) we can compile and dump the next arrow, Otherwise (and believe me you will frequently) should be reviewed for possible errors and correct them. We will return to this in the future.
The yellow arrow in our program the Arduino capsized and can see that the light flashes pin 13 with a delay of one second between on and off.
* Tip: If we change the values of the delay, modify the rate of blinking.
* Note: This will not work with any other Pin Arduino UNO, because only 13 has an LED connected.
No hay comentarios:
Publicar un comentario