Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Arduino Counter With LCD Display
- //For using with HD44780 LCD Shield
- #include <LiquidCrystal.h>
- LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
- 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;
- const char bigDigitsTop[10][digitWidth]={ 3,0,3, 0,3,32, 2,2,3, 0,2,3, 3,1,3,
- 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];
- void setup ()
- {
- lcd.begin(16,2);
- for(int i=0; i < 5; i++)
- lcd.createChar(i, glyphs[i]);
- for(int digit = 0; digit <= 9; digit++)
- {
- showDigit(digit, 2);
- delay(1000);
- }
- lcd.clear();
- }
- void loop ()
- {
- int number = millis() / 1000;
- showNumber( number, 0);
- delay(1000);
- }
- void showDigit(int digit, int position)
- {
- lcd.setCursor(position * (digitWidth + 1), 0);
- for(int i=0; i < digitWidth; i++)
- lcd.write(bigDigitsTop[digit][i]);
- lcd.setCursor(position * (digitWidth + 1), 1);
- for(int i=0; i < digitWidth; i++)
- lcd.write(bigDigitsBot[digit][i]);
- }
- void showNumber(int value, int position)
- {
- int index;
- itoa(value, buffer, 10);
- for(index = 0; index < 10; index++)
- {
- char c = buffer[index];
- if( c == 0)
- return;
- c = c - 48;
- showDigit(c, position + index);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement