From e4c0ca275fd940b545d0be54e68544c73980904a Mon Sep 17 00:00:00 2001 From: "rjbatista@gmail.com" Date: Wed, 11 Jan 2012 01:40:58 +0000 Subject: [PATCH] Support for the TM1640 --- CHANGES.txt | 2 + TM1640.cpp | 38 ++++++++++++++++++ TM1640.h | 45 ++++++++++++++++++++++ examples/tm1640_example/tm1640_example.pde | 36 +++++++++++++++++ 4 files changed, 121 insertions(+) create mode 100644 TM1640.cpp create mode 100644 TM1640.h create mode 100644 examples/tm1640_example/tm1640_example.pde diff --git a/CHANGES.txt b/CHANGES.txt index 56e9704..5d5bcbe 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,3 +1,5 @@ +- Restructuring for supporting other modules. + Version 1.6.0 - ISSUE #10: Support for starting position on setDisplayToString() methods. diff --git a/TM1640.cpp b/TM1640.cpp new file mode 100644 index 0000000..506bf47 --- /dev/null +++ b/TM1640.cpp @@ -0,0 +1,38 @@ +/* +TM1640.cpp - Library implementation for TM1640. + +Copyright (C) 2011 Ricardo Batista (rjbatista gmail com) + +This program is free software: you can redistribute it and/or modify +it under the terms of the version 3 GNU General Public License as +published by the Free Software Foundation. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ + +#if defined(ARDUINO) && ARDUINO >= 100 + #include "Arduino.h" +#else + #include "WProgram.h" +#endif + +#include "TM1640.h" +#include "string.h" + + +TM1640::TM1640(byte dataPin, byte clockPin, boolean activateDisplay, byte intensity) + : TM16XX(dataPin, clockPin, dataPin, 16, activateDisplay, intensity) +{ + // nothing else to do - calling super is enough +} + +void TM1640::sendChar(byte pos, byte data, boolean dot) +{ + sendData(pos, data | (dot ? 0b10000000 : 0)); +} diff --git a/TM1640.h b/TM1640.h new file mode 100644 index 0000000..d470eca --- /dev/null +++ b/TM1640.h @@ -0,0 +1,45 @@ +/* +TM1640.h - Library for TM1640. + +Copyright (C) 2011 Ricardo Batista + +This program is free software: you can redistribute it and/or modify +it under the terms of the version 3 GNU General Public License as +published by the Free Software Foundation. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ + +#ifndef TM1640_h +#define TM1640_h + +#if defined(ARDUINO) && ARDUINO >= 100 + #include "Arduino.h" +#else + #include "WProgram.h" +#endif + +#include "TM16XX.h" +#include "TM16XXFonts.h" + +class TM1640 : public TM16XX +{ + public: + /** Instantiate a tm1640 module specifying the display state, the starting intensity (0-7) data and clock pins. */ + TM1640(byte dataPin, byte clockPin, boolean activateDisplay = true, byte intensity = 7); + + /** Set the display to a unsigned decimal number (with or without leading zeros) */ + void setDisplayToDecNumber(unsigned long number, word dots, boolean leadingZeros = true, + const byte numberFont[] = NUMBER_FONT); + + protected: + virtual void sendChar(byte pos, byte data, boolean dot); +}; + +#endif diff --git a/examples/tm1640_example/tm1640_example.pde b/examples/tm1640_example/tm1640_example.pde new file mode 100644 index 0000000..f6e7e24 --- /dev/null +++ b/examples/tm1640_example/tm1640_example.pde @@ -0,0 +1,36 @@ +/* +Library examples for TM1640. + +Copyright (C) 2011 Ricardo Batista + +This program is free software: you can redistribute it and/or modify +it under the terms of the version 3 GNU General Public License as +published by the Free Software Foundation. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ +#include // required because the way arduino deals with libraries +#include + +// define a module on data pin 3, clock pin 2 +TM1640 module(3, 2); + +void setup() +{ + // nothing to do here +} + +void loop() +{ + char text[17]; + + sprintf(text, "testing %u", millis()); + + module.setDisplayToString(text); +}