Skip to content

Instantly share code, notes, and snippets.

@ronivaldo
Created May 15, 2013 21:02
Show Gist options
  • Save ronivaldo/5587355 to your computer and use it in GitHub Desktop.
Save ronivaldo/5587355 to your computer and use it in GitHub Desktop.
A set of custom made large numbers for a 16x2 LCD HD44780 Arduino Library
/*
A set of custom made large numbers for a 16x2 LCD using the
LiquidCrystal librabry. Works with displays compatible with the
Hitachi HD44780 driver.
The Cuicuit:
LCD RS pin to D12
LCD Enable pin to D11
LCD D4 pin to D5
LCD D5 pin to D4
LCD D6 pin to D3
LCD D7 pin to D2
LCD Vee tied to a pot to control brightness
LCD Vss and R/W tied to ground
LCD Vcc to +5V
Ronivaldo Sampaio (ronivaldo@gmail.com) for 3 lines
2013/05/15 -> change for character with only 3 lines
Original Made by Michael Pilcher
2/9/2010
character created using:
http://mikeyancey.com/hamcalc/lcd_characters.php
*/
// include the library
#include <LiquidCrystal.h>
// initialize the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
// the 8 arrays that form each segment of the custom numbers
byte bar1[8] =
{
B11100,
B11110,
B11110,
B11110,
B11110,
B11110,
B11110,
B11100
};
byte bar2[8] =
{
B00111,
B01111,
B01111,
B01111,
B01111,
B01111,
B01111,
B00111
};
byte bar3[8] =
{
B11111,
B11111,
B00000,
B00000,
B00000,
B00000,
B11111,
B11111
};
byte bar4[8] =
{
B11110,
B11100,
B00000,
B00000,
B00000,
B00000,
B11000,
B11100
};
byte bar5[8] =
{
B01111,
B00111,
B00000,
B00000,
B00000,
B00000,
B00011,
B00111
};
byte bar6[8] =
{
B00000,
B00000,
B00000,
B00000,
B00000,
B00000,
B11111,
B11111
};
byte bar7[8] =
{
B00000,
B00000,
B00000,
B00000,
B00000,
B00000,
B00111,
B01111
};
byte bar8[8] =
{
B11111,
B11111,
B00000,
B00000,
B00000,
B00000,
B00000,
B00000
};
void setup()
{
// assignes each segment a write number
lcd.createChar(1,bar1);
lcd.createChar(2,bar2);
lcd.createChar(3,bar3);
lcd.createChar(4,bar4);
lcd.createChar(5,bar5);
lcd.createChar(6,bar6);
lcd.createChar(7,bar7);
lcd.createChar(8,bar8);
// sets the LCD's rows and colums:
lcd.begin(16, 2);
}
void custom0(int col)
{ // uses segments to build the number 0
lcd.setCursor(col, 0);
lcd.write(2);
lcd.write(8);
lcd.write(1);
lcd.setCursor(col, 1);
lcd.write(2);
lcd.write(6);
lcd.write(1);
}
void custom1(int col)
{
lcd.setCursor(col,0);
lcd.write(32);
lcd.write(32);
lcd.write(1);
lcd.setCursor(col,1);
lcd.write(32);
lcd.write(32);
lcd.write(1);
}
void custom2(int col)
{
lcd.setCursor(col,0);
lcd.write(5);
lcd.write(3);
lcd.write(1);
lcd.setCursor(col, 1);
lcd.write(2);
lcd.write(6);
lcd.write(6);
}
void custom3(int col)
{
lcd.setCursor(col,0);
lcd.write(5);
lcd.write(3);
lcd.write(1);
lcd.setCursor(col, 1);
lcd.write(7);
lcd.write(6);
lcd.write(1);
}
void custom4(int col)
{
lcd.setCursor(col,0);
lcd.write(2);
lcd.write(6);
lcd.write(1);
lcd.setCursor(col, 1);
lcd.write(32);
lcd.write(32);
lcd.write(1);
}
void custom5(int col)
{
lcd.setCursor(col,0);
lcd.write(2);
lcd.write(3);
lcd.write(4);
lcd.setCursor(col, 1);
lcd.write(7);
lcd.write(6);
lcd.write(1);
}
void custom6(int col)
{
lcd.setCursor(col,0);
lcd.write(2);
lcd.write(3);
lcd.write(4);
lcd.setCursor(col, 1);
lcd.write(2);
lcd.write(6);
lcd.write(1);
}
void custom7(int col)
{
lcd.setCursor(col,0);
lcd.write(2);
lcd.write(8);
lcd.write(1);
lcd.setCursor(col, 1);
lcd.write(32);
lcd.write(32);
lcd.write(1);
}
void custom8(int col)
{
lcd.setCursor(col, 0);
lcd.write(2);
lcd.write(3);
lcd.write(1);
lcd.setCursor(col, 1);
lcd.write(2);
lcd.write(6);
lcd.write(1);
}
void custom9(int col)
{
lcd.setCursor(col, 0);
lcd.write(2);
lcd.write(3);
lcd.write(1);
lcd.setCursor(col, 1);
lcd.write(7);
lcd.write(6);
lcd.write(1);
}
void printNumber(int value, int col) {
if (value == 0) {
custom0(col);
} if (value == 1) {
custom1(col);
} if (value == 2) {
custom2(col);
} if (value == 3) {
custom3(col);
} if (value == 4) {
custom4(col);
} if (value == 5) {
custom5(col);
} if (value == 6) {
custom6(col);
} if (value == 7) {
custom7(col);
} if (value == 8) {
custom8(col);
} if (value == 9) {
custom9(col);
}
}
void printRPM(int rpm) {
int m , c, d, u, number;
number = rpm;
if (number > 999) {
m = (number - (number % 1000)) / 1000;
number = number % 1000;
} else {
m = 0;
}
if (number > 99) {
c = (number - (number % 100)) / 100;
number = number % 100;
} else {
c = 0;
}
if (number > 9) {
d = (number - (number % 10)) / 10;
number = number % 10;
} else {
d = 0;
}
u = number;
lcd.setCursor(0, 0);
lcd.print("RPM: ");
printNumber(m, 4);
printNumber(c, 7);
printNumber(d, 10);
printNumber(u, 13);
}
void loop()
{
printRPM(millis() % 10000);
delay(200);
}
@Greolt
Copy link

Greolt commented May 4, 2015

Thanks very much for sharing. This was exactly what I was looking for. A few more lines of code and I have the tacho working and looking just like I wanted.

@ronivaldo
Copy link
Author

Greolt, you are welcome! It's a pleasure help others.

@PauloMalas
Copy link

Ronivaldo, obrigado pela partilha

@PauloMalas
Copy link

Greolt also publish your code, with the alterations you say, the community thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment