Lesson 19-2: Measuring Voltage from a Potentiometer and Displaying it on Screen
In this lecture, we learn how to use LCD screens: both 2-line and 4-line LCDs (LCD1602 and LCD2004). We first learn about the module, then we learn how to get the I2C address for the module, then we learn how to display text on both lines.
A counter example, which counts from 0, is shown. Then we learn how to measure the DC voltage from a variable resistor (or potentiometer).
555-Lesson 19: Arduino code to read voltage and display it on LCD1602 or LCD2024
语言: C++
/*
* Robojax Arduino Step-by-Step Course
* Introduction to LCD
* Lesson 19-2 Potentiometer on LCD1602
* This code has been modified from the Arduino library
Please watch video instructions here https://youtu.be/pxUjEsJQW2M
This code is available at http://robojax.com/course1/?vid=lecture11
with over 100 lectures free on YouTube. Watch it here http://robojax.com/L/?id=338
Get the code for the course: http://robojax.com/L/?id=339
* Updated by Ahmad Shamshiri for Robojax on December 26, 2018
* in Ajax, Ontario, Canada
* com
*
* This is code for LCD1602 Display with I2C module
* which can display text on the screen.
*
* This code is "AS IS" without warranty or liability. Free to be used as long as you keep this note intact.
* This code has been downloaded from Robojax.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// Set the LCD address to 0x27 for a 16 or 20 chars and 2 or 4 lines display
LiquidCrystal_I2C lcd(0x27, 16, 2);
int count =700;
void setup()
{
//Robojax Arduino Step-by-Step Course http://robojax.com/L/?id=338
// Robojax code for LCD with I2C
// initialize the LCD,
lcd.begin();
// Turn on the backlight and print a message.
lcd.backlight();
// Robojax code for LCD with I2C
}
void loop()
{
//Robojax Arduino Step-by-Step Course http://robojax.com/L/?id=338
int potValue = analogRead(A0);
float voltage = potValue * (5.0 / 1023.0);
//start of loop Robojax code for LCD with I2C
lcd.clear();
lcd.print("LCD1602 Tutorial");
lcd.setCursor (0,1); // go to start of 2nd line
lcd.print("Voltage:");
lcd.setCursor (9,1); // set to line 2 char 9
lcd.print(voltage);
lcd.setCursor (13,1); // set to line 2 char 14
lcd.print("V");
//lcd.setCursor (3,3); // set to line 4 character 4
//lcd.print("Text in line 4");
delay(1000);
count++;
//end of loopcode Robojax code for LCD with I2C
}
资源与参考
-
外部RoboJax 的 LCD 库 (ZIP)robojax.com
文件📁
没有可用的文件。