Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Reddit bargraph LCD voltmeter - version 3.0 - 11 October 2019
- This should print the volts value on line 1.
- The second line should be a left-to-right bar graph between two left and right pointers:
- >>###########<<
- */
- #include <LiquidCrystal.h>
- int Vpin = 0;
- float voltaje;
- float V;
- LiquidCrystal lcd(7, 6, 5, 4, 3, 2); // pines RS, E, D4, D5, D6, D7 de modulo 1602A
- byte DIV_0_OF_5[8] = { // This is really the same as printing a space [ ]
- 0b00000,
- 0b00000,
- 0b00000,
- 0b00000,
- 0b00000,
- 0b00000,
- 0b00000,
- 0b00000
- }; // 0 / 5
- byte DIV_1_OF_5[8] = {
- 0b10000,
- 0b10000,
- 0b10000,
- 0b10000,
- 0b10000,
- 0b10000,
- 0b10000,
- 0b10000
- }; // 1 / 5
- byte DIV_2_OF_5[8] = {
- 0b11000,
- 0b11000,
- 0b11000,
- 0b11000,
- 0b11000,
- 0b11000,
- 0b11000,
- 0b11000
- }; // 2 / 5
- byte DIV_3_OF_5[8] = {
- 0b11100,
- 0b11100,
- 0b11100,
- 0b11100,
- 0b11100,
- 0b11100,
- 0b11100,
- 0b11100
- }; // 3 / 5
- byte DIV_4_OF_5[8] = {
- 0b11110,
- 0b11110,
- 0b11110,
- 0b11110,
- 0b11110,
- 0b11110,
- 0b11110,
- 0b11110
- }; // 4 / 5
- byte DIV_5_OF_5[8] = {
- 0b11111,
- 0b11111,
- 0b11111,
- 0b11111,
- 0b11111,
- 0b11111,
- 0b11111,
- 0b11111
- }; // 5 / 5
- byte right_pointer[8] = {
- 0b11000,
- 0b01100,
- 0b00110,
- 0b00011,
- 0b00011,
- 0b00110,
- 0b01100,
- 0b11000
- }; // A character like this >>
- byte left_pointer[8] = {
- 0b00011,
- 0b00110,
- 0b01100,
- 0b11000,
- 0b11000,
- 0b01100,
- 0b00110,
- 0b00011
- }; // A character like this <<
- /**
- Fonction de configuration de l'écran LCD pour la barre de progression.
- Utilise les caractéres personnalisés de 0 à 5 (6 et 7 restent disponibles).
- */
- // You can use the function below, but it must be called in setup() after the lcd.begin() call.
- void setup_progressbar() {
- /* Enregistre les caractères personnalisés dans la mémoire de l'écran LCD */
- lcd.createChar(0, DIV_0_OF_5);
- lcd.createChar(1, DIV_1_OF_5);
- lcd.createChar(2, DIV_2_OF_5);
- lcd.createChar(3, DIV_3_OF_5);
- lcd.createChar(4, DIV_4_OF_5);
- lcd.createChar(5, DIV_5_OF_5);
- lcd.createChar(6, right_pointer);
- lcd.createChar(7, left_pointer);
- }
- void setup() {
- lcd.begin(16, 2); // inicializa a display de 16 columnas y 2 lineas
- lcd.clear(); // to clear any possible random chars from starting up
- setup_progressbar();
- // Writing to an LCD takes time, so you want to avoid re-writing characters that will not change.
- // The characters below will not change, so they don't need to be re-written.
- lcd.setCursor(0, 0);
- lcd.print("SondaV= "); // The start position for V value is (8,0)
- lcd.setCursor(0, 1); // This should be the left-most character on line 2.
- lcd.write(byte(6));
- lcd.setCursor(13, 1); // This should be the char at the right end of the bar code range.
- lcd.write(byte(7));
- }
- void loop() {
- voltaje = analogRead (Vpin);
- V = voltaje / 1024 * 5.0;
- lcd.setCursor(8, 0);
- lcd.print(" ");
- lcd.setCursor(8, 0);
- lcd.print(V);
- display_bargraph1();
- delay(500);
- }
- void display_bargraph1() {
- lcd.setCursor(1, 1);
- // 1.1 voltage, .2 char divisions, displayed over 11 chars,,,,
- float base_voltage = 0;
- for (int i = 1; i <= 11; i++) {
- if (V >= (base_voltage + 1)) {
- lcd.write(byte(5));
- }
- else if (V >= (base_voltage + .08)) {
- lcd.write(byte(4));
- }
- else if (V >= (base_voltage + .06)) {
- lcd.write(byte(3));
- }
- else if (V >= (base_voltage + .04)) {
- lcd.write(byte(2));
- }
- else if (V >= (base_voltage + .02)) {
- lcd.write(byte(1));
- }
- else {
- lcd.write(" "); // This just writes a regular space.
- // Or, you could use custom character (zero) below--
- //lcd.write(byte(0)); // ------------------> but this is the same as printing a space.
- }
- base_voltage = base_voltage + .1;
- }
- }
- // ~~~~~~~~ the end ~~~~~~~~~
Add Comment
Please, Sign In to add comment