Well the last post was more of first connection and didn't include any explanation of the program (I'll be using sketch instead of program from now on) itself. Apologies for that but now I am going to discuss the functions used in basic Arduino programming. Let us start with the structure of an Arduino IDE sketch:
As you can see the code is divided into two parts. Both have their own significance as discussed below:-
Part I (void setup())
In this part you write commands that are to be executed only once after the Arduino is powered or RESET. Generally different digital pins are assigned as input/output pins and some variables (if required) are initialized. As the name suggests this function setups the Arduino ready for work.
Part II (void loop)
This part consist of repetitive program that keeps on executing till any of the program statement stops the execution. The name itself proclaims that the code in it will continue looping.
If you go back to our very basic BLINK program then you will find some basic functions which are discussed below:
1. pinMode():-This function tells the Arduino which Digital pins are Input or Output. For using it in IDE you will have to use 2 essential elements along it namely the pin which is being designated a position and the work it is supposed to do (Take input or give output). Statement 1 in the program above declares digital pin 13 as output.
2. digitalWrite():-This function tells the micro controller to output +5 volts on any given pin (Namely pin 13 in above statement). This function needs to be used along with two values : first the pin number on which output signal is to be given and whether the output is to be a +5 volt or 0 volt.
3. delay():-This function instructs the arduino board to let a given amount of time pass before executing the next instruction. The value entered in the () brackets is the time delay in milliseconds.
4. digitalRead():-This function (not used above) tells the board to input the signal at a given pin. Its syntax is as :
digitalRead("pin_number");
5. analogRead():- This function reads the analog voltage from the required analog input pin. Its syntax is same as digitalRead.
6. analogWrite():- This function allows you to write an analog voltage in the range 0-5 volts.
NOTE!@!@!@~Arduino IDE is case sensitive so Delay() or digitalwrite() will not work@!@!@!. Also all the lines written between these fancy symbol combo(/* */) are nothing but multi line comments to make the sketch more user friendly. Also // bull.......hit is a single line comment and does not bothers the IDE.
The last two functions will be discussed later in detail with examples. Well that's all for now. Stay tuned...
As you can see the code is divided into two parts. Both have their own significance as discussed below:-
Part I (void setup())
In this part you write commands that are to be executed only once after the Arduino is powered or RESET. Generally different digital pins are assigned as input/output pins and some variables (if required) are initialized. As the name suggests this function setups the Arduino ready for work.
Part II (void loop)
This part consist of repetitive program that keeps on executing till any of the program statement stops the execution. The name itself proclaims that the code in it will continue looping.
If you go back to our very basic BLINK program then you will find some basic functions which are discussed below:
1. pinMode():-This function tells the Arduino which Digital pins are Input or Output. For using it in IDE you will have to use 2 essential elements along it namely the pin which is being designated a position and the work it is supposed to do (Take input or give output). Statement 1 in the program above declares digital pin 13 as output.
2. digitalWrite():-This function tells the micro controller to output +5 volts on any given pin (Namely pin 13 in above statement). This function needs to be used along with two values : first the pin number on which output signal is to be given and whether the output is to be a +5 volt or 0 volt.
3. delay():-This function instructs the arduino board to let a given amount of time pass before executing the next instruction. The value entered in the () brackets is the time delay in milliseconds.
4. digitalRead():-This function (not used above) tells the board to input the signal at a given pin. Its syntax is as :
digitalRead("pin_number");
5. analogRead():- This function reads the analog voltage from the required analog input pin. Its syntax is same as digitalRead.
6. analogWrite():- This function allows you to write an analog voltage in the range 0-5 volts.
NOTE!@!@!@~Arduino IDE is case sensitive so Delay() or digitalwrite() will not work@!@!@!. Also all the lines written between these fancy symbol combo(/* */) are nothing but multi line comments to make the sketch more user friendly. Also // bull.......hit is a single line comment and does not bothers the IDE.
The last two functions will be discussed later in detail with examples. Well that's all for now. Stay tuned...
No comments:
Post a Comment