Hello All!
I'm working on a project inspired by the following instructable: http://www.instructables.com/id/Custom-Large-Font-For-16x2-LCDs/. I've got a 16x2 LCD with a keypad on it attached to a crane scale. Unfortunately, the numbers are too small on a single line, so I'm trying to use a large font over two lines. To test the programming, I've got an LCD Keypad shield attached to an Uno and am reading values from the keypads on A0. If the analog value is under 1000, it displays beautifully on the screen. If it's over 1000, however, the hundreds digit is cut off. If you have a similar setup, could you load my program and give any insight as to what I might be doing wrong? I suspect the problem lies in the section of code where I'm breaking down the analog value from thousands to hundreds, to tens, to ones, but I can't quite figure it out. I'm so close! Any help is greatly appreciated.
Here's the code:
#include <LiquidCrystal.h>
//Initial program Made by Michael Pilcher
//2/9/2010
//Modified and customized by Nick Pulver
//8/28/2013
// These constants won't change. They're used to give names
// to the pins used:
const int analogInPin = A0; // Analog input pin that the potentiometer is attached to
int sensorValue = 0; // value read from the pot
int outputValue = 0; // value output to the PWM (analog out)
//char outputValueChar[5];
int thousands;
int hundreds;
int tens;
int ones;
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
// the 8 arrays that form each segment of the custom numbers
byte A[8] =
{
B00111,
B01111,
B11111,
B11111,
B11111,
B11111,
B11111,
B11111
};
byte B[8] =
{
B11111,
B11111,
B11111,
B00000,
B00000,
B00000,
B00000,
B00000
};
byte C[8] =
{
B11100,
B11110,
B11111,
B11111,
B11111,
B11111,
B11111,
B11111
};
byte D[8] =
{
B11111,
B11111,
B11111,
B11111,
B11111,
B11111,
B01111,
B00111
};
byte E[8] =
{
B00000,
B00000,
B00000,
B00000,
B00000,
B11111,
B11111,
B11111
};
byte F[8] =
{
B11111,
B11111,
B11111,
B11111,
B11111,
B11111,
B11110,
B11100
};
byte G[8] =
{
B11111,
B11111,
B11111,
B00000,
B00000,
B00000,
B11111,
B11111
};
byte H[8] =
{
B11111,
B00000,
B00000,
B00000,
B00000,
B11111,
B11111,
B11111
};
// loop counter
int x = 0;
void setup()
{
Serial.begin(9600);
// assignes each segment a write number
lcd.createChar(0,A);
lcd.createChar(1,B);
lcd.createChar(2,C);
lcd.createChar(3,D);
lcd.createChar(4,E);
lcd.createChar(5,F);
lcd.createChar(6,G);
lcd.createChar(7,H);
// sets the LCD's rows and colums:
lcd.begin(16, 2);
}
void custom0()
{ // uses segments to build the number 0
lcd.setCursor(x, 0); // set cursor to column 0, line 0 (first row)
lcd.write((byte)0); // call each segment to create
lcd.write(1); // top half of the number
lcd.write(2);
lcd.setCursor(x, 1); // set cursor to colum 0, line 1 (second row)
lcd.write(3); // call each segment to create
lcd.write(4); // bottom half of the number
lcd.write(5);
}
void custom1()
{
lcd.setCursor(x,0);
lcd.write(1);
lcd.write(2);
lcd.write(32);
lcd.setCursor(x,1);
lcd.write(32);
lcd.write(255);
lcd.write(32);
}
void custom2()
{
lcd.setCursor(x,0);
lcd.write(6);
lcd.write(6);
lcd.write(2);
lcd.setCursor(x, 1);
lcd.write(3);
lcd.write(7);
lcd.write(7);
}
void custom3()
{
lcd.setCursor(x,0);
lcd.write(6);
lcd.write(6);
lcd.write(2);
lcd.setCursor(x, 1);
lcd.write(7);
lcd.write(7);
lcd.write(5);
}
void custom4()
{
lcd.setCursor(x,0);
lcd.write(3);
lcd.write(4);
lcd.write(2);
lcd.setCursor(x, 1);
lcd.write(32);
lcd.write(32);
lcd.write(255);
}
void custom5()
{
lcd.setCursor(x,0);
lcd.write((byte)0);
lcd.write(6);
lcd.write(6);
lcd.setCursor(x, 1);
lcd.write(7);
lcd.write(7);
lcd.write(5);
}
void custom6()
{
lcd.setCursor(x,0);
lcd.write((byte)0);
lcd.write(6);
lcd.write(6);
lcd.setCursor(x, 1);
lcd.write(3);
lcd.write(7);
lcd.write(5);
}
void custom7()
{
lcd.setCursor(x,0);
lcd.write(1);
lcd.write(1);
lcd.write(2);
lcd.setCursor(x, 1);
lcd.write(32);
lcd.write((byte)0);
lcd.write(32);
}
void custom8()
{
lcd.setCursor(x,0);
lcd.write((byte)0);
lcd.write(6);
lcd.write(2);
lcd.setCursor(x, 1);
lcd.write(3);
lcd.write(7);
lcd.write(5);
}
void custom9()
{
lcd.setCursor(x,0);
lcd.write((byte)0);
lcd.write(6);
lcd.write(2);
lcd.setCursor(x, 1);
lcd.write(32);
lcd.write(32);
lcd.write(255 );
}
void loop() {
// read the analog in value:
outputValue = analogRead(analogInPin);
// map it to the range of the analog out:
// print the results to the serial monitor:
Serial.print("output = ");
Serial.println(outputValue);
String stringOne = String(outputValue);
x=0;
//THIS IS WHERE I THINK THE PROBLEM LIES
/*The following section breaks down the analog value
into thousands, hundreds, tens, ones, and attaches them to
a custom large-font number*/
thousands = outputValue /1000;
delay(500);
switch(thousands)
{
case 5:
custom5();
break;
case 4:
custom4();
break;
case 3:
custom3();
break;
case 2:
custom2();
break;
case 1:
custom1();
break;
case 0:
custom0();
break;
}
hundreds = outputValue /100;
delay(500);
switch (hundreds) {
case 9:
custom9();
break;
case 8:
custom8();
break;
case 7:
custom7();
break;
case 6:
custom6();
break;
case 5:
custom5();
break;
case 4:
custom4();
break;
case 3:
custom3();
break;
case 2:
custom2();
break;
case 1:
custom1();
break;
case 0:
custom0();
break;
}
tens=outputValue /10;
tens=tens%10;
switch (tens) {
case 9:
x=x+4;
custom9();
break;
case 8:
x=x+4;
custom8();
break;
case 7:
x=x+3;
custom7();
break;
case 6:
x=x+4;
custom6();
break;
case 5:
x=x+4;
custom5();
break;
case 4:
x=x+4;
custom4();
break;
case 3:
x=x+4;
custom3();
break;
case 2:
x=x+4;
custom2();
break;
case 1:
x=x+4;
custom1();
break;
if (outputValue<10)
{
//case 0:
x=x+4;
custom0();
break;
}
case 0:
x=x+4;
custom0();
break;
}
ones=outputValue%10;
//ones=ones%100;
// Serial.println(ones);
switch (ones) {
case 9:
x=x+4;
custom9();
break;
case 8:
x=x+4;
custom8();
break;
case 7:
x=x+4;
custom7();
break;
case 6:
x=x+4;
custom6();
break;
case 5:
x=x+4;
custom5();
break;
case 4:
x=x+4;
custom4();
break;
case 3:
x=x+4;
custom3();
break;
case 2:
x=x+4;
custom2();
break;
case 1:
x=x+4;
custom1();
break;
case 0:
x=x+4;
custom0();
break;
}
}
