Thanks for that.
I have added some big custom numbers to the display, so it shows a custom number and a text name, one problem i am having is after the 2nd display number and name the text gets stuck ie instead of the display showing "3 Lead it displays 3 leadch or 4 drive it displays 4 driveh can some tell me how to fix this.
The code is as follows...
/*
* customChars
*
* This sketch displays double-height digits
* the bigDigit arrays were inspired by Arduino forum member dcb
*/
//#include <LiquidCrystal.h>
#include <Wire.h>
// 2. for the LCD functions
#include <LiquidCrystal_I2C.h>
int button = 4;
int count = 0;
int upLastTime, downLastTime, upNow, downNow;
LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
byte glyphs[5][8] = {
{ B11111,B11111,B00000,B00000,B00000,B00000,B00000,B00000 } ,
{ B00000,B00000,B00000,B00000,B00000,B00000,B11111,B11111 } ,
{ B11111,B11111,B00000,B00000,B00000,B00000,B11111,B11111 } ,
{ B11111,B11111,B11111,B11111,B11111,B11111,B11111,B11111 } ,
{ B00000,B00000,B00000,B00000,B00000,B01110,B01110,B01110 } };
const int digitWidth = 3; // the width in characters of a big digit (excludes space between characters)
//arrays to index into custom characters that will comprise the big numbers
// digits 0 - 4 0 1 2 3 4
const char bigDigitsTop[10][digitWidth]={ 3,0,3, 0,3,32, 2,2,3, 0,2,3, 3,1,3,
// digits 5-9 5 6 7 8 9
3,2,2, 3,2,2, 0,0,3, 3,2,3, 3,2,3};
const char bigDigitsBot[10][ digitWidth]={ 3,1,3, 1,3,1, 3,1,1, 1,1,3, 32,32,3,
1,1,3, 3,1,3, 32,32,3, 3,1,3, 1,1,3};
char buffer[12]; // used to convert a number into a string
void setup ()
{
pinMode (button,INPUT_PULLUP);
lcd.begin(16,2);
lcd.setCursor(3, 0); // top left
lcd.print("ENIGMA ver1");
// create the custom glyphs
for(int i=0; i < 5; i++)
lcd.createChar(i, glyphs[i]); // create the 5 custom glyphs
// show a countdown timer
// for(int digit = 9; digit >= 0; digit--)
//{
//showDigit(digit, 2); // show the digit
delay(1000);
// }
lcd.clear();
}
void loop ()
{
upNow = digitalRead(button);
if (upNow == HIGH && upLastTime == LOW) {
//lcd.setCursor(0,0);
//lcd.print(count++);
//showNumber( count++, 0);
int disp = count++;
switch (disp) {
case 0:
//lcd.clear();
lcd.setCursor(6,0);
lcd.print("Clean");
lcd.setCursor(0,0);
showNumber(count,0);
break;
case 1:
// lcd.clear();
lcd.setCursor(6,0);
lcd.print("Crunch");
lcd.setCursor(0,0);
showNumber(count,0);
break;
case 2:
// lcd.clear();
lcd.setCursor(6,0);
lcd.print("Lead");
lcd.setCursor(0,0);
showNumber(count,0);
break;
case 3:
// lcd.clear();
lcd.setCursor(6,0);
lcd.print("Drive");
showNumber(count,0);
break;
default:
lcd.setCursor(5,0);
lcd.clear();
lcd.setCursor(0,0);
showNumber(count,0);
break;
}
delay(20); // bit of debounce delay
}
upLastTime= upNow;
}
void showDigit(int digit, int position)
{
lcd.setCursor(position * (digitWidth + 1), 0);
for(int i=0; i < digitWidth; i++)
lcd.print(bigDigitsTop[digit][i]);
lcd.setCursor(position * (digitWidth + 1), 1);
for(int i=0; i < digitWidth; i++)
lcd.print(bigDigitsBot[digit][i]);
}
void showNumber(int value, int position)
{
int index; // index to the digit being printed, 0 is the leftmost digit
itoa(value, buffer, 10); // see Recipe 2.8 for more on using itoa
// dislay each digit in sequence
for(index = 0; index < 10; index++) // display up to ten digits
{
char c = buffer[index];
if( c == 0) // check for null (not the same as '0')
return; // the end of string character is a null, see Chapter 2
c = c - 48; // convert ascii value to a numeric value (see Recipe 2.9)
showDigit(c, position + index);
}
}[code]