Advertisement
Braulio777

Arduino Counter LCD Display

Nov 3rd, 2014
877
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Arduino Counter With LCD Display
  2. //For using with HD44780 LCD Shield
  3. #include <LiquidCrystal.h>
  4. LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
  5. byte glyphs[5][8] = {
  6. { B11111,B11111,B00000,B00000,B00000,B00000,B00000,B00000 },
  7. { B00000,B00000,B00000,B00000,B00000,B00000,B11111,B11111 },
  8. { B11111,B11111,B00000,B00000,B00000,B00000,B11111,B11111 },
  9. { B11111,B11111,B11111,B11111,B11111,B11111,B11111,B11111 },
  10. { B00000,B00000,B00000,B00000,B00000,B01110,B01110,B01110 } };
  11. const int digitWidth = 3;
  12. const char bigDigitsTop[10][digitWidth]={ 3,0,3, 0,3,32, 2,2,3, 0,2,3, 3,1,3,
  13. 3,2,2, 3,2,2, 0,0,3, 3,2,3, 3,2,3};
  14. const char bigDigitsBot[10][digitWidth]={ 3,1,3, 1,3,1, 3,1,1, 1,1,3, 32,32,3,
  15. 1,1,3, 3,1,3, 32,32,3, 3,1,3, 1,1,3};
  16. char buffer[12];
  17. void setup ()
  18. {
  19. lcd.begin(16,2);
  20. for(int i=0; i < 5; i++)
  21. lcd.createChar(i, glyphs[i]);
  22. for(int digit = 0; digit <= 9; digit++)
  23. {
  24. showDigit(digit, 2);
  25. delay(1000);
  26. }
  27. lcd.clear();
  28. }
  29. void loop ()
  30. {
  31. int number = millis() / 1000;
  32. showNumber( number, 0);
  33. delay(1000);
  34. }
  35. void showDigit(int digit, int position)
  36. {
  37. lcd.setCursor(position * (digitWidth + 1), 0);
  38. for(int i=0; i < digitWidth; i++)
  39. lcd.write(bigDigitsTop[digit][i]);
  40. lcd.setCursor(position * (digitWidth + 1), 1);
  41. for(int i=0; i < digitWidth; i++)
  42. lcd.write(bigDigitsBot[digit][i]);
  43. }
  44. void showNumber(int value, int position)
  45. {
  46. int index;
  47. itoa(value, buffer, 10);
  48. for(index = 0; index < 10; index++)
  49. {
  50. char c = buffer[index];
  51. if( c == 0)
  52. return;
  53. c = c - 48;
  54. showDigit(c, position + index);
  55. }
  56. }
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement