/*
Unit Converter
Chris G
8/20/23
#include <LiquidCrystal.h>
#include <Keypad.h>
//////// Display
LiquidCrystal lcd(12, 11, 10, 9, 8, 7);
//////// Keypad setup
const byte KEYPAD_ROWS = 4;
const byte KEYPAD_COLS = 4;
byte rowPins[KEYPAD_ROWS] = {5, 4, 3, 2};
byte colPins[KEYPAD_COLS] = {A3, A2, A1, A0};
char keys[KEYPAD_ROWS][KEYPAD_COLS] = {
{'1', '2', '3', 'i'},
{'4', '5', '6', 'm'},
{'7', '8', '9'},
{'.', '0', ' ', 'c'}
};
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, KEYPAD_ROWS, KEYPAD_COLS);
void setup() {
Serial.begin(115200);
lcd.begin(16, 2);
lcd.clear();
lcd.cursor();
lcd.setCursor(0, 0);
}
const float Ratio = 25.4; //in to mm conversion ratio
String current = "";
float memory;
float converted;
void processInput(char key) {
//////// Conversion Buttons
//// Convert in to mm
if ('i' == key) {
memory = current.toFloat();
converted = memory * Ratio;
current = "";
lcd.clear();
lcd.setCursor(0, 1);
lcd.print(converted, 4); lcd.print("mm");
lcd.setCursor(0, 0);
return;
}
//// Convert mm to in
if ('m' == key){
memory = current.toFloat();
converted = memory / Ratio;
current = "";
lcd.clear();
lcd.setCursor(0, 1);
lcd.print(converted, 4); lcd.print("in");
lcd.setCursor(0, 0);
return;
}
//////// Only allows typing 1 decimal point
if ('.' == key && current.indexOf('.') >= 0) {
return;
}
if ('.' != key && current == "0") {
current = String(key);
} else if (key) {
current += String(key);
}
//////// Clear button
if ('c' == key){
lcd.clear();
current = "";
memory = 0;
return;
}
lcd.print(key);
}
void loop() {
char key = keypad.getKey();
if (key) {
processInput(key);
}
}
*/
#include <LiquidCrystal.h> // include the library
LiquidCrystal lcd(12, 11, 10, 9, 8, 7); // define the arduino pins
//rs, en, d4, d5, d6, d7 lcd pins
// Define 16x2 LCD
int screenWidth = 16;
int screenHeight = 2;
// To move ONLY one line needs to move one character at a time
// Define two line
String line1 = " LCD ep3: "; // stationary
String line2 = " This is a one line scrolling tutorial! "; // scroll this line
int stringStart, stringEnd = 0;
int scrollCursor = screenWidth;
void setup() {
lcd.begin(screenWidth, screenHeight);
}
void loop() {
lcd.setCursor(0, 0); // Seting the cursor on first row
lcd.print(line1); // To print line1 message
lcd.setCursor(scrollCursor, 1); // Seting the cursor on first row and (scrolling from left end to right)
lcd.print(line2.substring(stringStart,stringEnd)); // To print line1 first character "T"
delay(500);
lcd.clear(); // clear message
if(stringStart == 0 && scrollCursor > 0){
scrollCursor--; // Moving cursor from 16 to 0
stringEnd++; // Character T, H, I, S ...
// it will print out character from 0 to 15 the whole length of the screen
}
else if (stringStart == stringEnd){ // start all over again
stringStart = stringEnd = 0;
scrollCursor = screenWidth;
}
else if (stringEnd == line1.length() && scrollCursor == 0) { // if reach to the end character
stringStart++;
}
else { // it will print out character from (1 to 16) to end character (this case it's !))
stringStart++;
stringEnd++;
}
}