Question

In: Electrical Engineering

what is the following (ARDUINO): -Libraries are code that allow -Lcd. setCursor (x,y) -Where to Import...

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

Solutions

Expert Solution

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


Related Solutions

We need to code an LCD with a temperature and humidity sensor for the arduino UNO...
We need to code an LCD with a temperature and humidity sensor for the arduino UNO board. The LCD should simply display the temperature and humidity reading from the DHT11 sensor. We must do this without the use of arduino or lcd libraries, and only use raw c code. For example we need to use PORTD |= (1<<5); to set the pin to 5. The LCD is connected to pins A0 and A1, and it is using I2C. The temperature...
Suppose x is 1 and y is 10. What is the output of the following code?...
Suppose x is 1 and y is 10. What is the output of the following code?                         If (x> 1) && ( y <11)                                     Display statement                         else                                     Display nothing 2. Suppose x is 1 and y is 10. What is the output of the following code?                         If (x> 1) || ( y <11)                                     Display statement                         Else                                     Display nothing 3. Write a java program that prints 1 to infinite numbers. 4. The...
Can somebody describe what this following code does step by step. import turtle turtle.penup() x =...
Can somebody describe what this following code does step by step. import turtle turtle.penup() x = int(input("Enter x coordinate of top-left corner: ")) y = int(input("Enter y coordinate of top-left corner: ")) side = int(input("Enter side of the largest square: ")) if side >= 100: gap = int(input("Enter gap between squares: ")) if gap < side: turtle.goto(x,y) turtle.pendown() while True: for i in range(4): turtle.forward(side) turtle.right(90) side -=gap turtle.penup() x += gap y -= gap turtle.goto(x,y) turtle.pendown() if side<0: exit(1)
what is the following (ARDUINO): -Examples of a standard Arduino library -The Arduino uses a structured...
what is the following (ARDUINO): -Examples of a standard Arduino library -The Arduino uses a structured programming language-what type -Channels of A/D conversion on the Arduino Uno -The Arduino correlates temperature readings with what
Write the following Python code: A string X is an anagram of string Y if X...
Write the following Python code: A string X is an anagram of string Y if X can be obtained by arranging all characters of Y in some order, without removing any characters and without adding new characters. For example, each of the strings "baba", "abab", "aabb" and "abba" is an anagram of "aabb", and strings "aaab", "aab" and "aabc" are not anagrams of "aabb". A set of strings is anagram-free if it contains no pair of strings which are anagrams...
THIS IS FOR ARDUINO PROGRAMMING Write code that checks the sensor data and meets the following...
THIS IS FOR ARDUINO PROGRAMMING Write code that checks the sensor data and meets the following conditions: For night conditions, turn on white LED 1 For day conditions, turn off white LED 1 Code should check intervals every 5 seconds. NEED THE BELOW CODE TO FIT THE ABOVE REQUIREMENTS. const int lightSensor = 5; //light sensor variable float sensValue = 0; //variable to hold sensor readings const int button = 3; //pin for button reads const int LED1 = 5;...
Where to Import a library into a given code Digital pins can be used to Analog...
Where to Import a library into a given code Digital pins can be used to Analog pins can be used to AnalogReadSerial: What pins on the Arduino can be assigned as… The Arduino uses what to assign analog values? Examples of a standard Arduino library The Arduino uses a structured programming language-what type Channels of A/D conversion on the Arduino Uno The Arduino correlates temperature readings with what
Suppose that the utility function of a consumer is U(x,y) = x ¼y ¾, where x...
Suppose that the utility function of a consumer is U(x,y) = x ¼y ¾, where x and y are the quantities of the good X and good Y consumed, respectively. The consumer's income is 400. (a) What is the demanded bundle when the price of good X is 10 and the price of good Y is 10? (b) Redo part (a) when the price of good X is doubled? (c) Redo part (a) when the price of good Y is...
Consider walks in the X-Y plane where each step is R: (x, y)→(x+1, y) or U:...
Consider walks in the X-Y plane where each step is R: (x, y)→(x+1, y) or U: (x, y)→(x, y+a), with a a positive integer. There are five walks that contain a point on the line x + y = 2, namely:  RR, RU1, U1R, U1U1, and U2. Let a_n denote the number of walks that contain a point on the line x + y = n (so a_2 = 5). Show that a_n = F_{2n}, where F_n are the Fibonacci numbers...
Consider this code snippet: if (x < 512) { y = 73; } else { y...
Consider this code snippet: if (x < 512) { y = 73; } else { y = 42; } Which of these goto-style code snippets is equivalent to that if/else code? Consider this code snippet: if (x < 512) { y = 73; } else { y = 42; } Which of these goto-style code snippets is equivalent to that if/else code? a. if (x >= 512) goto Label1; y = 73; goto Label2; Label1: y = 42; Label2: b....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT