Professional Documents
Culture Documents
Laboratorio microcontroladores #7
Objetivos
Utilizar una pantalla de Cristal Lquido (LCD) para mostrar los mensajes.
Controlar un teclado numrico con la placa Arduino.
Materiales
1 un Arduino UNO
1 cable USB
1 Protoboard
1 LCD
1 teclado numerico
1 potenciometro de 10K
1 LM35
cables
Procedimiento Usado:
Se combinaron y adaptaron el boceto en el apartado 5.5 del Arduino
Cookbook, y el programa del anexo1, para la realizacin las siguientes
tareas:
a) Muestra su nombre en la pantalla LCD, una lnea.
b) Espere 2 segundos.
c) Borrar la pantalla.
d) Visualizar el mensaje " Enter your selection " en la primera lnea, y "
Type(1) GRADE C or(2) GRADE F " en la segunda lnea de la pantalla.
e) Lea sus valores de seleccin desde el teclado y mostrar el valor de
temperatura en la segunda lnea.
f) Si se presiona otra tecla, la pantalla LCD borra la pantalla, espera por
2 segundos, y muestra el mensaje en la parte (d).
Diagrama De Flujo
Cdigo Arduino
#include <LiquidCrystal.h>
#include <Keypad.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
float tempC;
int tempPin = 0;
float far=0;
const int numRows = 4; // number of rows in the keypad
const int numCols = 4; // number of columns
const int debounceTime = 20; // number of milliseconds for switch to be
stable
// keymap defines the character returned when the corresponding key is
pressed
const char keymap[numRows][numCols] = {
{ '1', '2', '3', 'A'} ,
{ '4', '5', '6', 'B'} ,
{ '7', '8', '9', 'C'} ,
{ '*', '0', '#', 'D'}
};
// this array determines the pins used for rows and columns
const int rowPins[numRows] = { 6, 7, 8, 9 }; // Rows 0 through 3
const int colPins[numCols] = { 10, 13, A5, A4 }; // Columns 0 through 2
void setup()
{
lcd.begin(16,2);
lcd.setCursor(0,0);
lcd.print("Anderson Zuniga ");
delay(2000);
lcd.clear();
lcd.scrollDisplayLeft();
lcd.setCursor(16,1);
lcd.setCursor(0,0);
lcd.print("Enter your selection");
lcd.setCursor(0,1);
lcd.print("Type(1) GRADE C or(2) GRADE F");
Serial.begin(9600);
for (int row = 0; row < numRows; row++)
{
pinMode(rowPins[row],INPUT); // Set row pins as input
digitalWrite(rowPins[row],HIGH); // turn on Pull-ups
}
for (int column = 0; column < numCols; column++)
{
pinMode(colPins[column],OUTPUT); // Set column pins as outputs for
writing
digitalWrite(colPins[column],HIGH); // Make all columns inactive
}
}
void loop()
{
tempC = analogRead(tempPin);
tempC = (5.0*tempC*100.0)/1024.0;
far = (tempC*1.8)+ 32;
char key =getKey();// almacenar en la posicion contador la tecla
pulsada
if (key != NO_KEY){// Si se puls alguna tecla entonces
switch (key){
case '1':
lcd.clear();
case1();
break;
case '2':
lcd.clear();
case2();
break;
default:
lcd.clear();
delay(2000);
lcd.print("Enter your selection");
lcd.setCursor(0,1);
lcd.print("Type(1) GRADE C or(2) GRADE F");
;}
}
lcd.scrollDisplayLeft();
lcd.setCursor(16,1);
lcd.setCursor(0,0);
delay(400);}
// returns with the key pressed, or 0 if no key is pressed
char getKey()
{
char key = 0; // 0 indicates no key pressed
for(int column = 0; column < numCols; column++)
{
digitalWrite(colPins[column],LOW); // Activate the current column.
for(int row = 0; row < numRows; row++) // Scan all rows for a key press.
{
Circuito
Discusin y conclusiones
Las instrucciones char key =getkey() y no_key fueron sacadas de la
pgina oficial de arduino y trabajan con la librera keypad.h.
El anexo 1 tiene un cdigo proporcionado por el profesor en la
correspondiente gua de laboratorio.
Anexo 1
Cdigo de termmetro
//declare variables
float tempC;
int tempPin = 0;
void setup()
{
Serial.begin(9600); //opens serial port, sets data rate to 9600 bps
}
void loop()
{
tempC = analogRead(tempPin); //read the value from the sensor
tempC = (5.0*tempC*100.0)/1024.0; //convert the analog data to C
Serial.print((byte)tempC); //send the data to the computer
delay(1000); //wait one second
}