/*
* This is how to write a block comment.
*
* Not all LCD displays are the same,
* maybe this matches your 16 x 2 LCD.
* I have the display that is in this video.
* https://www.youtube.com/watch?v=4BaDaGTUgIY
*
* This is where you can get more information
* http://www.arduino.cc/en/Tutorial/LiquidCrystal
*
* Library originally added 18 Apr 2008
* by David A. Mellis
* library modified 5 Jul 2009
* by Limor Fried (http://www.ladyada.net)
* example added 9 Jul 2009
* by Tom Igoe
* modified 22 Nov 2010
* by Tom Igoe
* modified 7 Nov 2016
* by Arturo Guadalupi
* modified 30 Jan 2022
* by Edoctoor
*
* https://wokwi.com/arduino/projects/321995158308520530
*
* This example code is in the public domain.
* http://www.arduino.cc/en/Tutorial/LiquidCrystalHelloWorld
*
*/
// include the LiquidCrystal.h library
#include <LiquidCrystal.h>
/*
* initialize the library with the interface pins values
* First create the variables and assign the values
* because LiquidCrystal lcd(7, 6, 12, 10, 9, 8);
* will not tell you what wire goes where.
*
* TIP: Do the GND and POWER wires after you have made
* all other connections and you have checked your
* schematic several times.
*
* Connect the LCD wires to the pins on the Arduino
*
* Pin LCD Descriptions:
* Pin 1 --- Ground
* Pin 2 --- VDD Power for the LCD
* Pin 3 --- Contrast Adjust
* Pin 4 --- Register Select (RS)
* Pin 5 --- Read / Write select (R/W)
* Pin 6 --- Enable (E)
* Pin 7 --- not used
* Pin 8 --- not used
* Pin 9 --- not used
* Pin 10 -- not used
* Pin 11 -- Data line (D4) 4-bits at a time
* Pin 12 -- Data line (D5) 4-bits at a time
* Pin 13 -- Data line (D6) 4-bits at a time
* Pin 14 -- Data line (D7) 4-bits at a time
* Pin 15 -- Backlight Power
* Pin 16 -- Backlight Ground (GND) remember 220 ohms resistor
*
*/
// Double slash for adding single line comments
const int rs = 7; // Pin 7 on Arduino to pin 4 (RS) on LCD
const int en = 6; // Pin 6 on Arduino to pin 6 (E) on LCD
const int d4 = 12; // Pin 12 on Arduino to pin 11 (D4) on LCD
const int d5 = 10; // Pin 10 on Arduino to pin 12 (D5) on LCD
const int d6 = 9; // Pin 9 on Arduino to pin 13 (D6) on LCD
const int d7 = 8; // Pin 8 on Arduino to pin 14 (D7) on LCD
/*
10k potentiometer
Connect swipe pin of the potentiometer to the VO pin on the 16 x 2 LCD
Lastly the Ground (Black) and power wires (Red)
from the Arduino to the following pins on the LCD display
GND = VSS, RW, and (K with 220 ohms)
POWER = VDD, A
*/
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
byte customChar[] = {
B00000,
B00000,
B00000,
B00000,
B00000,
B00000,
B00000,
B11111
};
char numberArray[10];
char arr[10];
char floatStr[10];
char *pointer[] = { "uno", "due", "pro"};
float val;
int move = 2;
int select = 3;
void setup() {
// Set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print Hello World! to the LCD.
lcd.createChar(0, customChar);
pinMode(A0,INPUT);
pinMode(move, INPUT_PULLUP);
pinMode(select, INPUT_PULLUP);
}
unsigned long now,prev = 0;
unsigned long interval = 500;
int i = 0;
int pointer_val = 0;
void loop() {
val = analogRead(A0) * (5.0/1023.0)*3;
dtostrf(val, -6, 2, floatStr); // 6 char min total width, 2 after decimal -. left justified. so -
//sprintf(numberArray, "%s", floatStr );
//snprintf(numberArray, sizeof(numberArray),"%s", floatStr); // more good.
now = millis();
lcd.setCursor(0,0);
lcd.print("VOLT: ");
lcd.setCursor(5,0);
lcd.print(floatStr);
lcd.setCursor(0,1);
sprintf(arr, "%s", pointer[i] );
lcd.print(arr);
lcd.setCursor(13,0);
lcd.print(pointer[pointer_val]);
if(digitalRead(move) == LOW){
i = i + 1;
if(i == 3) {i = 0;}
}
if(digitalRead(select) == LOW)
{
pointer_val = i;
}
// if((now-prev) >= interval)
// {
// i = i+1;
// if(i == 3) {i = 0;}
// prev = now;
// }
}