TM16XX.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. TM16XX.h - Library for TM1638.
  3. Copyright (C) 2011 Ricardo Batista <rjbatista at gmail dot com>
  4. This program is free software: you can redistribute it and/or modify
  5. it under the terms of the version 3 GNU General Public License as
  6. published by the Free Software Foundation.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. */
  14. #ifndef TM16XX_h
  15. #define TM16XX_h
  16. // #define TM1618_DEBUG 1
  17. #if defined(ARDUINO) && ARDUINO >= 100
  18. #include "Arduino.h"
  19. #else
  20. #include "WProgram.h"
  21. #endif
  22. #include "TM16XXFonts.h"
  23. class TM16XX
  24. {
  25. public:
  26. /**
  27. * Instantiate a tm16xx module specifying the number of displays, display state,
  28. * the starting intensity (0-7) data, clock and stobe pins.
  29. */
  30. TM16XX(byte dataPin, byte clockPin, byte strobePin, byte displays, boolean activateDisplay = true,
  31. byte intensity = 7);
  32. /** Set the display (segments and LEDs) active or off and intensity (range from 0-7). */
  33. virtual void setupDisplay(boolean active, byte intensity);
  34. /** Set a single display at pos (starting at 0) to a digit (left to right) */
  35. virtual void setDisplayDigit(byte digit, byte pos, boolean dot, const byte numberFont[] = NUMBER_FONT);
  36. /** Set the display to an error message */
  37. virtual void setDisplayToError();
  38. /** Clear a single display at pos (starting at 0, left to right) */
  39. virtual void clearDisplayDigit(byte pos, boolean dot);
  40. /** Set the display to the values (left to right) */
  41. virtual void setDisplay(const byte values[], unsigned int length = 8);
  42. /** Clear the display */
  43. virtual void clearDisplay();
  44. /** Set the display to the string (defaults to built in font) */
  45. virtual void setDisplayToString(const char* string, const word dots = 0, const byte pos = 0,
  46. const byte font[] = FONT_DEFAULT);
  47. /** Set the display to the String (defaults to built in font) */
  48. virtual void setDisplayToString(String string, const word dots = 0, const byte pos = 0,
  49. const byte font[] = FONT_DEFAULT);
  50. protected:
  51. #if defined(ARDUINO) && ARDUINO >= 100
  52. // pure virtual is NOT supported in older Arduino IDE
  53. virtual void sendChar(byte pos, byte data, boolean dot) = 0;
  54. #else
  55. virtual void sendChar(byte pos, byte data, boolean dot);
  56. #endif
  57. virtual void sendCommand(byte led);
  58. virtual void sendData(byte add, byte data);
  59. virtual void send(byte data);
  60. virtual byte receive();
  61. byte displays;
  62. byte dataPin;
  63. byte clockPin;
  64. byte strobePin;
  65. };
  66. #endif