In: Electrical Engineering
what is the following (ARDUINO):
-Libraries are code that allow
-Lcd. setCursor (x,y)
-Where to Import a library into a given code
-Digital pins can be used to
1. As the name itself indicates , in programming, a library is a collection of precompiled resources which we can reuse in programing . In Aurdino libraries are a collection of code that makes it easy for you to connect to a sensor, display, module, etc. When you coding big application, it's good to reuse precompiled libraries .
Hence a library promotes code reusability and reduces the length of the code.
These are files written in C or C++ (.c, .cpp) which provide your sketches with extra functionality such as working with hardware or manipulating data
A sketch is the name that Arduino uses for a program. It's the unit of code that is uploaded and executed on aurdino board
A number of libraries come installed with the IDE, but you can also download or create your own.
The following are some of the inbuilt libraries -
1. Servo - for controlling servo motors
2 GSM - for connecting to a GSM/GRPS network with the GSM shield.
3 LiquidCrystal - for controlling liquid crystal displays (LCDs)
lets take an example of displaying hello world on a LCD (consider the coding part ) -
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 =
2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
* the above two rows are for initialising the LCD and the ports
that are connecte to it *
void setup() {
lcd.begin(16, 2);
* set up the LCD's number of columns and rows:*
lcd.print("hello, world!");
* displaying message on LCD *
}
void loop() {
* set the cursor to column 0, line 1 *
lcd.setCursor(0, 1);
lcd.print(millis() / 1000);
*wait time *
}
2. setCursor (x,Y) is the syntax to position the LCD cursor ie, set the location at which subsequent text written to the LCD will be displayed.
The general syntax is
lcd.setCursor(col, row)
where
lcd: a variable of type LiquidCrystal
col: the column at which to position the cursor (with 0 being the first column)
row: the row at which to position the cursor (with 0 being the first row)
For example
lcd.setCursor(15, 1); // bottom right
lcd.setCursor(0, 1); // bottom left
Lets take an exmple-
for a 2x16 display means it has 2 rows and 16 columns of characters, or 2 y values and 16 x values.
We start our count with 0 hence to get the first column you need to tell the Arduino to look at x of 0. or tell the Arduino to move the cursor to: (15, 0).
3. Whenever you want to use a library you have to call the header file first -
Lets take an example of a stepper motor taking one revolution -
Stepper is the library used for controlling stepper motors-
#include <Stepper.h> ------------ header file for using
the stepper library
const int stepsPerRevolution = 200;
* number of steps per revolution can be taken depending upon
the steps requried for a particular stepper motor for completing
one complete revolution *
* initialize the stepper library on pins 8 through 11 on the
aurdino board *
Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);
void setup() {
myStepper.setSpeed(60);
*setting speed to 60rpm*
* initialize the serial port:*
Serial.begin(9600);
}
void loop() {
* step one revolution in a particular direction:*
Serial.println("clockwise");
myStepper.step(stepsPerRevolution);
delay(500);
* step one revolution in the opposite direction: *
Serial.println("counterclockwise");
myStepper.step(-stepsPerRevolution);
*negative sign indicates the anticlockwise direction *
delay(500);
}
The stepper motor will revolve first clockwise , wait for 500 seconds and then revolve anticlockwise.
4. Arduino Uno has 14 digital input/output pins Lets see what they are used for
These pins can be used as a input or output pins.These pins can be used for both digital input (like telling if a button is pushed) and digital output (like powering an LED).
Digital Ground - the pin coloured light green are for ground
Digital Pins - pin numbers from 2-13 coloured green are the digital pins
Digital Pins - 0-1/Serial In/Out - TX/RX dark green these pins cannot be used to digital read or digital write