初始化提交
This commit is contained in:
4
arduino-cli/libraries/TM1637-master/.gitignore
vendored
Normal file
4
arduino-cli/libraries/TM1637-master/.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
.idea
|
||||
.pioenvs
|
||||
.clang_complete
|
||||
.gcc-flags.json
|
||||
63
arduino-cli/libraries/TM1637-master/.travis.yml
Normal file
63
arduino-cli/libraries/TM1637-master/.travis.yml
Normal file
@@ -0,0 +1,63 @@
|
||||
# Continuous Integration (CI) is the practice, in software
|
||||
# engineering, of merging all developer working copies with a shared mainline
|
||||
# several times a day < http://docs.platformio.org/en/latest/ci/index.html >
|
||||
#
|
||||
# Documentation:
|
||||
#
|
||||
# * Travis CI Embedded Builds with PlatformIO
|
||||
# < https://docs.travis-ci.com/user/integration/platformio/ >
|
||||
#
|
||||
# * PlatformIO integration with Travis CI
|
||||
# < http://docs.platformio.org/en/latest/ci/travis.html >
|
||||
#
|
||||
# * User Guide for `platformio ci` command
|
||||
# < http://docs.platformio.org/en/latest/userguide/cmd_ci.html >
|
||||
#
|
||||
#
|
||||
# Please choice one of the following templates (proposed below) and uncomment
|
||||
# it (remove "# " before each line) or use own configuration according to the
|
||||
# Travis CI documentation (see above).
|
||||
#
|
||||
|
||||
|
||||
#
|
||||
# Template #1: General project. Test it using existing `platformio.ini`.
|
||||
#
|
||||
|
||||
# language: python
|
||||
# python:
|
||||
# - "2.7"
|
||||
#
|
||||
# sudo: false
|
||||
# cache:
|
||||
# directories:
|
||||
# - "~/.platformio"
|
||||
#
|
||||
# install:
|
||||
# - pip install -U platformio
|
||||
#
|
||||
# script:
|
||||
# - platformio run
|
||||
|
||||
|
||||
#
|
||||
# Template #2: The project is intended to by used as a library with examples
|
||||
#
|
||||
|
||||
language: python
|
||||
python:
|
||||
- "2.7"
|
||||
|
||||
sudo: false
|
||||
cache:
|
||||
directories:
|
||||
- "~/.platformio"
|
||||
|
||||
env:
|
||||
- PLATFORMIO_CI_SRC=examples/TM1637Test/TM1637Test.ino
|
||||
|
||||
install:
|
||||
- pip install -U platformio
|
||||
|
||||
script:
|
||||
- platformio ci --lib="." --board=nodemcuv2 --board=ethernet
|
||||
165
arduino-cli/libraries/TM1637-master/LICENSE
Normal file
165
arduino-cli/libraries/TM1637-master/LICENSE
Normal file
@@ -0,0 +1,165 @@
|
||||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
|
||||
This version of the GNU Lesser General Public License incorporates
|
||||
the terms and conditions of version 3 of the GNU General Public
|
||||
License, supplemented by the additional permissions listed below.
|
||||
|
||||
0. Additional Definitions.
|
||||
|
||||
As used herein, "this License" refers to version 3 of the GNU Lesser
|
||||
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
||||
General Public License.
|
||||
|
||||
"The Library" refers to a covered work governed by this License,
|
||||
other than an Application or a Combined Work as defined below.
|
||||
|
||||
An "Application" is any work that makes use of an interface provided
|
||||
by the Library, but which is not otherwise based on the Library.
|
||||
Defining a subclass of a class defined by the Library is deemed a mode
|
||||
of using an interface provided by the Library.
|
||||
|
||||
A "Combined Work" is a work produced by combining or linking an
|
||||
Application with the Library. The particular version of the Library
|
||||
with which the Combined Work was made is also called the "Linked
|
||||
Version".
|
||||
|
||||
The "Minimal Corresponding Source" for a Combined Work means the
|
||||
Corresponding Source for the Combined Work, excluding any source code
|
||||
for portions of the Combined Work that, considered in isolation, are
|
||||
based on the Application, and not on the Linked Version.
|
||||
|
||||
The "Corresponding Application Code" for a Combined Work means the
|
||||
object code and/or source code for the Application, including any data
|
||||
and utility programs needed for reproducing the Combined Work from the
|
||||
Application, but excluding the System Libraries of the Combined Work.
|
||||
|
||||
1. Exception to Section 3 of the GNU GPL.
|
||||
|
||||
You may convey a covered work under sections 3 and 4 of this License
|
||||
without being bound by section 3 of the GNU GPL.
|
||||
|
||||
2. Conveying Modified Versions.
|
||||
|
||||
If you modify a copy of the Library, and, in your modifications, a
|
||||
facility refers to a function or data to be supplied by an Application
|
||||
that uses the facility (other than as an argument passed when the
|
||||
facility is invoked), then you may convey a copy of the modified
|
||||
version:
|
||||
|
||||
a) under this License, provided that you make a good faith effort to
|
||||
ensure that, in the event an Application does not supply the
|
||||
function or data, the facility still operates, and performs
|
||||
whatever part of its purpose remains meaningful, or
|
||||
|
||||
b) under the GNU GPL, with none of the additional permissions of
|
||||
this License applicable to that copy.
|
||||
|
||||
3. Object Code Incorporating Material from Library Header Files.
|
||||
|
||||
The object code form of an Application may incorporate material from
|
||||
a header file that is part of the Library. You may convey such object
|
||||
code under terms of your choice, provided that, if the incorporated
|
||||
material is not limited to numerical parameters, data structure
|
||||
layouts and accessors, or small macros, inline functions and templates
|
||||
(ten or fewer lines in length), you do both of the following:
|
||||
|
||||
a) Give prominent notice with each copy of the object code that the
|
||||
Library is used in it and that the Library and its use are
|
||||
covered by this License.
|
||||
|
||||
b) Accompany the object code with a copy of the GNU GPL and this license
|
||||
document.
|
||||
|
||||
4. Combined Works.
|
||||
|
||||
You may convey a Combined Work under terms of your choice that,
|
||||
taken together, effectively do not restrict modification of the
|
||||
portions of the Library contained in the Combined Work and reverse
|
||||
engineering for debugging such modifications, if you also do each of
|
||||
the following:
|
||||
|
||||
a) Give prominent notice with each copy of the Combined Work that
|
||||
the Library is used in it and that the Library and its use are
|
||||
covered by this License.
|
||||
|
||||
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
||||
document.
|
||||
|
||||
c) For a Combined Work that displays copyright notices during
|
||||
execution, include the copyright notice for the Library among
|
||||
these notices, as well as a reference directing the user to the
|
||||
copies of the GNU GPL and this license document.
|
||||
|
||||
d) Do one of the following:
|
||||
|
||||
0) Convey the Minimal Corresponding Source under the terms of this
|
||||
License, and the Corresponding Application Code in a form
|
||||
suitable for, and under terms that permit, the user to
|
||||
recombine or relink the Application with a modified version of
|
||||
the Linked Version to produce a modified Combined Work, in the
|
||||
manner specified by section 6 of the GNU GPL for conveying
|
||||
Corresponding Source.
|
||||
|
||||
1) Use a suitable shared library mechanism for linking with the
|
||||
Library. A suitable mechanism is one that (a) uses at run time
|
||||
a copy of the Library already present on the user's computer
|
||||
system, and (b) will operate properly with a modified version
|
||||
of the Library that is interface-compatible with the Linked
|
||||
Version.
|
||||
|
||||
e) Provide Installation Information, but only if you would otherwise
|
||||
be required to provide such information under section 6 of the
|
||||
GNU GPL, and only to the extent that such information is
|
||||
necessary to install and execute a modified version of the
|
||||
Combined Work produced by recombining or relinking the
|
||||
Application with a modified version of the Linked Version. (If
|
||||
you use option 4d0, the Installation Information must accompany
|
||||
the Minimal Corresponding Source and Corresponding Application
|
||||
Code. If you use option 4d1, you must provide the Installation
|
||||
Information in the manner specified by section 6 of the GNU GPL
|
||||
for conveying Corresponding Source.)
|
||||
|
||||
5. Combined Libraries.
|
||||
|
||||
You may place library facilities that are a work based on the
|
||||
Library side by side in a single library together with other library
|
||||
facilities that are not Applications and are not covered by this
|
||||
License, and convey such a combined library under terms of your
|
||||
choice, if you do both of the following:
|
||||
|
||||
a) Accompany the combined library with a copy of the same work based
|
||||
on the Library, uncombined with any other library facilities,
|
||||
conveyed under the terms of this License.
|
||||
|
||||
b) Give prominent notice with the combined library that part of it
|
||||
is a work based on the Library, and explaining where to find the
|
||||
accompanying uncombined form of the same work.
|
||||
|
||||
6. Revised Versions of the GNU Lesser General Public License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions
|
||||
of the GNU Lesser General Public License from time to time. Such new
|
||||
versions will be similar in spirit to the present version, but may
|
||||
differ in detail to address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Library as you received it specifies that a certain numbered version
|
||||
of the GNU Lesser General Public License "or any later version"
|
||||
applies to it, you have the option of following the terms and
|
||||
conditions either of that published version or of any later version
|
||||
published by the Free Software Foundation. If the Library as you
|
||||
received it does not specify a version number of the GNU Lesser
|
||||
General Public License, you may choose any version of the GNU Lesser
|
||||
General Public License ever published by the Free Software Foundation.
|
||||
|
||||
If the Library as you received it specifies that a proxy can decide
|
||||
whether future versions of the GNU Lesser General Public License shall
|
||||
apply, that proxy's public statement of acceptance of any version is
|
||||
permanent authorization for you to choose that version for the
|
||||
Library.
|
||||
27
arduino-cli/libraries/TM1637-master/README.md
Normal file
27
arduino-cli/libraries/TM1637-master/README.md
Normal file
@@ -0,0 +1,27 @@
|
||||
TM1637
|
||||
======
|
||||
Arduino library for TM1637 (LED Driver)
|
||||
|
||||
|
||||
Description
|
||||
-----------
|
||||
An Arduino library for 7-segment display modules based on the TM1637 chip, such as Seeed Studio's [Grove 4 digit display](http://www.seeedstudio.com/depot/grove-4digit-display-p-1198.html). The TM1637 chip also has keyboard input capability, but it's not implemented in this library.
|
||||
|
||||
Hardware Connection
|
||||
-------------------
|
||||
The display modules has two signal connection (and two power connections) which are CLK and DIO. These pins can be connected to any pair of digital pins on the Arduino. When an object is created, the pins should be configured. There is no limitation on the number of instances used concurrently (as long as each instance has a pin pair of its own)
|
||||
|
||||
Installation
|
||||
------------
|
||||
The library is installed as any Arduino library, by copying the files into a directory on the library search path of the Arduino IDE
|
||||
|
||||
Usage
|
||||
-----
|
||||
The library provides a single class named TM1637Display. An instance of this class provides the following functions:
|
||||
|
||||
* `setSegments` - Set the raw value of the segments of each digit
|
||||
* `showNumberDec` - Display a decimal number
|
||||
* `showNumberDecEx` - Display a decimal number with decimal points or colon
|
||||
* `setBrightness` - Sets the brightness of the display
|
||||
|
||||
The information given above is only a summary. Please refer to TM1637Display.h for more information. An example is included, demonstrating the operation of most of the functions.
|
||||
258
arduino-cli/libraries/TM1637-master/TM1637Display.cpp
Normal file
258
arduino-cli/libraries/TM1637-master/TM1637Display.cpp
Normal file
@@ -0,0 +1,258 @@
|
||||
|
||||
// Author: avishorp@gmail.com
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2.1 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library 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
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
extern "C" {
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <inttypes.h>
|
||||
}
|
||||
|
||||
#include <TM1637Display.h>
|
||||
#include <Arduino.h>
|
||||
|
||||
#define TM1637_I2C_COMM1 0x40
|
||||
#define TM1637_I2C_COMM2 0xC0
|
||||
#define TM1637_I2C_COMM3 0x80
|
||||
|
||||
//
|
||||
// A
|
||||
// ---
|
||||
// F | | B
|
||||
// -G-
|
||||
// E | | C
|
||||
// ---
|
||||
// D
|
||||
const uint8_t digitToSegment[] = {
|
||||
// XGFEDCBA
|
||||
0b00111111, // 0
|
||||
0b00000110, // 1
|
||||
0b01011011, // 2
|
||||
0b01001111, // 3
|
||||
0b01100110, // 4
|
||||
0b01101101, // 5
|
||||
0b01111101, // 6
|
||||
0b00000111, // 7
|
||||
0b01111111, // 8
|
||||
0b01101111, // 9
|
||||
0b01110111, // A
|
||||
0b01111100, // b
|
||||
0b00111001, // C
|
||||
0b01011110, // d
|
||||
0b01111001, // E
|
||||
0b01110001 // F
|
||||
};
|
||||
|
||||
static const uint8_t minusSegments = 0b01000000;
|
||||
|
||||
TM1637Display::TM1637Display(uint8_t pinClk, uint8_t pinDIO, unsigned int bitDelay)
|
||||
{
|
||||
// Copy the pin numbers
|
||||
m_pinClk = pinClk;
|
||||
m_pinDIO = pinDIO;
|
||||
m_bitDelay = bitDelay;
|
||||
|
||||
// Set the pin direction and default value.
|
||||
// Both pins are set as inputs, allowing the pull-up resistors to pull them up
|
||||
pinMode(m_pinClk, INPUT);
|
||||
pinMode(m_pinDIO,INPUT);
|
||||
digitalWrite(m_pinClk, LOW);
|
||||
digitalWrite(m_pinDIO, LOW);
|
||||
}
|
||||
|
||||
void TM1637Display::setBrightness(uint8_t brightness, bool on)
|
||||
{
|
||||
m_brightness = (brightness & 0x7) | (on? 0x08 : 0x00);
|
||||
}
|
||||
|
||||
void TM1637Display::setSegments(const uint8_t segments[], uint8_t length, uint8_t pos)
|
||||
{
|
||||
// Write COMM1
|
||||
start();
|
||||
writeByte(TM1637_I2C_COMM1);
|
||||
stop();
|
||||
|
||||
// Write COMM2 + first digit address
|
||||
start();
|
||||
writeByte(TM1637_I2C_COMM2 + (pos & 0x03));
|
||||
|
||||
// Write the data bytes
|
||||
for (uint8_t k=0; k < length; k++)
|
||||
writeByte(segments[k]);
|
||||
|
||||
stop();
|
||||
|
||||
// Write COMM3 + brightness
|
||||
start();
|
||||
writeByte(TM1637_I2C_COMM3 + (m_brightness & 0x0f));
|
||||
stop();
|
||||
}
|
||||
|
||||
void TM1637Display::clear()
|
||||
{
|
||||
uint8_t data[] = { 0, 0, 0, 0 };
|
||||
setSegments(data);
|
||||
}
|
||||
|
||||
void TM1637Display::showNumberDec(int num, bool leading_zero, uint8_t length, uint8_t pos)
|
||||
{
|
||||
showNumberDecEx(num, 0, leading_zero, length, pos);
|
||||
}
|
||||
|
||||
void TM1637Display::showNumberDecEx(int num, uint8_t dots, bool leading_zero,
|
||||
uint8_t length, uint8_t pos)
|
||||
{
|
||||
showNumberBaseEx(num < 0? -10 : 10, num < 0? -num : num, dots, leading_zero, length, pos);
|
||||
}
|
||||
|
||||
void TM1637Display::showNumberHexEx(uint16_t num, uint8_t dots, bool leading_zero,
|
||||
uint8_t length, uint8_t pos)
|
||||
{
|
||||
showNumberBaseEx(16, num, dots, leading_zero, length, pos);
|
||||
}
|
||||
|
||||
void TM1637Display::showNumberBaseEx(int8_t base, uint16_t num, uint8_t dots, bool leading_zero,
|
||||
uint8_t length, uint8_t pos)
|
||||
{
|
||||
bool negative = false;
|
||||
if (base < 0) {
|
||||
base = -base;
|
||||
negative = true;
|
||||
}
|
||||
|
||||
|
||||
uint8_t digits[4];
|
||||
|
||||
if (num == 0 && !leading_zero) {
|
||||
// Singular case - take care separately
|
||||
for(uint8_t i = 0; i < (length-1); i++)
|
||||
digits[i] = 0;
|
||||
digits[length-1] = encodeDigit(0);
|
||||
}
|
||||
else {
|
||||
//uint8_t i = length-1;
|
||||
//if (negative) {
|
||||
// // Negative number, show the minus sign
|
||||
// digits[i] = minusSegments;
|
||||
// i--;
|
||||
//}
|
||||
|
||||
for(int i = length-1; i >= 0; --i)
|
||||
{
|
||||
uint8_t digit = num % base;
|
||||
|
||||
if (digit == 0 && num == 0 && leading_zero == false)
|
||||
// Leading zero is blank
|
||||
digits[i] = 0;
|
||||
else
|
||||
digits[i] = encodeDigit(digit);
|
||||
|
||||
if (digit == 0 && num == 0 && negative) {
|
||||
digits[i] = minusSegments;
|
||||
negative = false;
|
||||
}
|
||||
|
||||
num /= base;
|
||||
}
|
||||
}
|
||||
|
||||
if(dots != 0)
|
||||
{
|
||||
showDots(dots, digits);
|
||||
}
|
||||
|
||||
setSegments(digits, length, pos);
|
||||
}
|
||||
|
||||
void TM1637Display::bitDelay()
|
||||
{
|
||||
delayMicroseconds(m_bitDelay);
|
||||
}
|
||||
|
||||
void TM1637Display::start()
|
||||
{
|
||||
pinMode(m_pinDIO, OUTPUT);
|
||||
bitDelay();
|
||||
}
|
||||
|
||||
void TM1637Display::stop()
|
||||
{
|
||||
pinMode(m_pinDIO, OUTPUT);
|
||||
bitDelay();
|
||||
pinMode(m_pinClk, INPUT);
|
||||
bitDelay();
|
||||
pinMode(m_pinDIO, INPUT);
|
||||
bitDelay();
|
||||
}
|
||||
|
||||
bool TM1637Display::writeByte(uint8_t b)
|
||||
{
|
||||
uint8_t data = b;
|
||||
|
||||
// 8 Data Bits
|
||||
for(uint8_t i = 0; i < 8; i++) {
|
||||
// CLK low
|
||||
pinMode(m_pinClk, OUTPUT);
|
||||
bitDelay();
|
||||
|
||||
// Set data bit
|
||||
if (data & 0x01)
|
||||
pinMode(m_pinDIO, INPUT);
|
||||
else
|
||||
pinMode(m_pinDIO, OUTPUT);
|
||||
|
||||
bitDelay();
|
||||
|
||||
// CLK high
|
||||
pinMode(m_pinClk, INPUT);
|
||||
bitDelay();
|
||||
data = data >> 1;
|
||||
}
|
||||
|
||||
// Wait for acknowledge
|
||||
// CLK to zero
|
||||
pinMode(m_pinClk, OUTPUT);
|
||||
pinMode(m_pinDIO, INPUT);
|
||||
bitDelay();
|
||||
|
||||
// CLK to high
|
||||
pinMode(m_pinClk, INPUT);
|
||||
bitDelay();
|
||||
uint8_t ack = digitalRead(m_pinDIO);
|
||||
if (ack == 0)
|
||||
pinMode(m_pinDIO, OUTPUT);
|
||||
|
||||
|
||||
bitDelay();
|
||||
pinMode(m_pinClk, OUTPUT);
|
||||
bitDelay();
|
||||
|
||||
return ack;
|
||||
}
|
||||
|
||||
void TM1637Display::showDots(uint8_t dots, uint8_t* digits)
|
||||
{
|
||||
for(int i = 0; i < 4; ++i)
|
||||
{
|
||||
digits[i] |= (dots & 0x80);
|
||||
dots <<= 1;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t TM1637Display::encodeDigit(uint8_t digit)
|
||||
{
|
||||
return digitToSegment[digit & 0x0f];
|
||||
}
|
||||
166
arduino-cli/libraries/TM1637-master/TM1637Display.h
Normal file
166
arduino-cli/libraries/TM1637-master/TM1637Display.h
Normal file
@@ -0,0 +1,166 @@
|
||||
// Author: avishorp@gmail.com
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2.1 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library 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
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
#ifndef __TM1637DISPLAY__
|
||||
#define __TM1637DISPLAY__
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
#define SEG_A 0b00000001
|
||||
#define SEG_B 0b00000010
|
||||
#define SEG_C 0b00000100
|
||||
#define SEG_D 0b00001000
|
||||
#define SEG_E 0b00010000
|
||||
#define SEG_F 0b00100000
|
||||
#define SEG_G 0b01000000
|
||||
#define SEG_DP 0b10000000
|
||||
|
||||
#define DEFAULT_BIT_DELAY 100
|
||||
|
||||
class TM1637Display {
|
||||
|
||||
public:
|
||||
//! Initialize a TM1637Display object, setting the clock and
|
||||
//! data pins.
|
||||
//!
|
||||
//! @param pinClk - The number of the digital pin connected to the clock pin of the module
|
||||
//! @param pinDIO - The number of the digital pin connected to the DIO pin of the module
|
||||
//! @param bitDelay - The delay, in microseconds, between bit transition on the serial
|
||||
//! bus connected to the display
|
||||
TM1637Display(uint8_t pinClk, uint8_t pinDIO, unsigned int bitDelay = DEFAULT_BIT_DELAY);
|
||||
|
||||
//! Sets the brightness of the display.
|
||||
//!
|
||||
//! The setting takes effect when a command is given to change the data being
|
||||
//! displayed.
|
||||
//!
|
||||
//! @param brightness A number from 0 (lowes brightness) to 7 (highest brightness)
|
||||
//! @param on Turn display on or off
|
||||
void setBrightness(uint8_t brightness, bool on = true);
|
||||
|
||||
//! Display arbitrary data on the module
|
||||
//!
|
||||
//! This function receives raw segment values as input and displays them. The segment data
|
||||
//! is given as a byte array, each byte corresponding to a single digit. Within each byte,
|
||||
//! bit 0 is segment A, bit 1 is segment B etc.
|
||||
//! The function may either set the entire display or any desirable part on its own. The first
|
||||
//! digit is given by the @ref pos argument with 0 being the leftmost digit. The @ref length
|
||||
//! argument is the number of digits to be set. Other digits are not affected.
|
||||
//!
|
||||
//! @param segments An array of size @ref length containing the raw segment values
|
||||
//! @param length The number of digits to be modified
|
||||
//! @param pos The position from which to start the modification (0 - leftmost, 3 - rightmost)
|
||||
void setSegments(const uint8_t segments[], uint8_t length = 4, uint8_t pos = 0);
|
||||
|
||||
//! Clear the display
|
||||
void clear();
|
||||
|
||||
//! Display a decimal number
|
||||
//!
|
||||
//! Display the given argument as a decimal number.
|
||||
//!
|
||||
//! @param num The number to be shown
|
||||
//! @param leading_zero When true, leading zeros are displayed. Otherwise unnecessary digits are
|
||||
//! blank. NOTE: leading zero is not supported with negative numbers.
|
||||
//! @param length The number of digits to set. The user must ensure that the number to be shown
|
||||
//! fits to the number of digits requested (for example, if two digits are to be displayed,
|
||||
//! the number must be between 0 to 99)
|
||||
//! @param pos The position of the most significant digit (0 - leftmost, 3 - rightmost)
|
||||
void showNumberDec(int num, bool leading_zero = false, uint8_t length = 4, uint8_t pos = 0);
|
||||
|
||||
//! Display a decimal number, with dot control
|
||||
//!
|
||||
//! Display the given argument as a decimal number. The dots between the digits (or colon)
|
||||
//! can be individually controlled.
|
||||
//!
|
||||
//! @param num The number to be shown
|
||||
//! @param dots Dot/Colon enable. The argument is a bitmask, with each bit corresponding to a dot
|
||||
//! between the digits (or colon mark, as implemented by each module). i.e.
|
||||
//! For displays with dots between each digit:
|
||||
//! * 0.000 (0b10000000)
|
||||
//! * 00.00 (0b01000000)
|
||||
//! * 000.0 (0b00100000)
|
||||
//! * 0.0.0.0 (0b11100000)
|
||||
//! For displays with just a colon:
|
||||
//! * 00:00 (0b01000000)
|
||||
//! For displays with dots and colons colon:
|
||||
//! * 0.0:0.0 (0b11100000)
|
||||
//! @param leading_zero When true, leading zeros are displayed. Otherwise unnecessary digits are
|
||||
//! blank. NOTE: leading zero is not supported with negative numbers.
|
||||
//! @param length The number of digits to set. The user must ensure that the number to be shown
|
||||
//! fits to the number of digits requested (for example, if two digits are to be displayed,
|
||||
//! the number must be between 0 to 99)
|
||||
//! @param pos The position of the most significant digit (0 - leftmost, 3 - rightmost)
|
||||
void showNumberDecEx(int num, uint8_t dots = 0, bool leading_zero = false, uint8_t length = 4, uint8_t pos = 0);
|
||||
|
||||
//! Display a hexadecimal number, with dot control
|
||||
//!
|
||||
//! Display the given argument as a hexadecimal number. The dots between the digits (or colon)
|
||||
//! can be individually controlled.
|
||||
//!
|
||||
//! @param num The number to be shown
|
||||
//! @param dots Dot/Colon enable. The argument is a bitmask, with each bit corresponding to a dot
|
||||
//! between the digits (or colon mark, as implemented by each module). i.e.
|
||||
//! For displays with dots between each digit:
|
||||
//! * 0.000 (0b10000000)
|
||||
//! * 00.00 (0b01000000)
|
||||
//! * 000.0 (0b00100000)
|
||||
//! * 0.0.0.0 (0b11100000)
|
||||
//! For displays with just a colon:
|
||||
//! * 00:00 (0b01000000)
|
||||
//! For displays with dots and colons colon:
|
||||
//! * 0.0:0.0 (0b11100000)
|
||||
//! @param leading_zero When true, leading zeros are displayed. Otherwise unnecessary digits are
|
||||
//! blank
|
||||
//! @param length The number of digits to set. The user must ensure that the number to be shown
|
||||
//! fits to the number of digits requested (for example, if two digits are to be displayed,
|
||||
//! the number must be between 0 to 99)
|
||||
//! @param pos The position of the most significant digit (0 - leftmost, 3 - rightmost)
|
||||
void showNumberHexEx(uint16_t num, uint8_t dots = 0, bool leading_zero = false, uint8_t length = 4, uint8_t pos = 0);
|
||||
|
||||
//! Translate a single digit into 7 segment code
|
||||
//!
|
||||
//! The method accepts a number between 0 - 15 and converts it to the
|
||||
//! code required to display the number on a 7 segment display.
|
||||
//! Numbers between 10-15 are converted to hexadecimal digits (A-F)
|
||||
//!
|
||||
//! @param digit A number between 0 to 15
|
||||
//! @return A code representing the 7 segment image of the digit (LSB - segment A;
|
||||
//! bit 6 - segment G; bit 7 - always zero)
|
||||
static uint8_t encodeDigit(uint8_t digit);
|
||||
|
||||
protected:
|
||||
void bitDelay();
|
||||
|
||||
void start();
|
||||
|
||||
void stop();
|
||||
|
||||
bool writeByte(uint8_t b);
|
||||
|
||||
void showDots(uint8_t dots, uint8_t* digits);
|
||||
|
||||
void showNumberBaseEx(int8_t base, uint16_t num, uint8_t dots = 0, bool leading_zero = false, uint8_t length = 4, uint8_t pos = 0);
|
||||
|
||||
|
||||
private:
|
||||
uint8_t m_pinClk;
|
||||
uint8_t m_pinDIO;
|
||||
uint8_t m_brightness;
|
||||
unsigned int m_bitDelay;
|
||||
};
|
||||
|
||||
#endif // __TM1637DISPLAY__
|
||||
BIN
arduino-cli/libraries/TM1637-master/docs/TM1637_ V2.4.pdf
Normal file
BIN
arduino-cli/libraries/TM1637-master/docs/TM1637_ V2.4.pdf
Normal file
Binary file not shown.
BIN
arduino-cli/libraries/TM1637-master/docs/TM1637_V2.4_EN.pdf
Normal file
BIN
arduino-cli/libraries/TM1637-master/docs/TM1637_V2.4_EN.pdf
Normal file
Binary file not shown.
@@ -0,0 +1,131 @@
|
||||
#include <Arduino.h>
|
||||
#include <TM1637Display.h>
|
||||
|
||||
// Module connection pins (Digital Pins)
|
||||
#define CLK 2
|
||||
#define DIO 3
|
||||
|
||||
// The amount of time (in milliseconds) between tests
|
||||
#define TEST_DELAY 2000
|
||||
|
||||
const uint8_t SEG_DONE[] = {
|
||||
SEG_B | SEG_C | SEG_D | SEG_E | SEG_G, // d
|
||||
SEG_A | SEG_B | SEG_C | SEG_D | SEG_E | SEG_F, // O
|
||||
SEG_C | SEG_E | SEG_G, // n
|
||||
SEG_A | SEG_D | SEG_E | SEG_F | SEG_G // E
|
||||
};
|
||||
|
||||
TM1637Display display(CLK, DIO);
|
||||
|
||||
void setup()
|
||||
{
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
int k;
|
||||
uint8_t data[] = { 0xff, 0xff, 0xff, 0xff };
|
||||
uint8_t blank[] = { 0x00, 0x00, 0x00, 0x00 };
|
||||
display.setBrightness(0x0f);
|
||||
|
||||
// All segments on
|
||||
display.setSegments(data);
|
||||
delay(TEST_DELAY);
|
||||
|
||||
// Selectively set different digits
|
||||
data[0] = display.encodeDigit(0);
|
||||
data[1] = display.encodeDigit(1);
|
||||
data[2] = display.encodeDigit(2);
|
||||
data[3] = display.encodeDigit(3);
|
||||
display.setSegments(data);
|
||||
delay(TEST_DELAY);
|
||||
|
||||
/*
|
||||
for(k = 3; k >= 0; k--) {
|
||||
display.setSegments(data, 1, k);
|
||||
delay(TEST_DELAY);
|
||||
}
|
||||
*/
|
||||
|
||||
display.clear();
|
||||
display.setSegments(data+2, 2, 2);
|
||||
delay(TEST_DELAY);
|
||||
|
||||
display.clear();
|
||||
display.setSegments(data+2, 2, 1);
|
||||
delay(TEST_DELAY);
|
||||
|
||||
display.clear();
|
||||
display.setSegments(data+1, 3, 1);
|
||||
delay(TEST_DELAY);
|
||||
|
||||
|
||||
// Show decimal numbers with/without leading zeros
|
||||
display.showNumberDec(0, false); // Expect: ___0
|
||||
delay(TEST_DELAY);
|
||||
display.showNumberDec(0, true); // Expect: 0000
|
||||
delay(TEST_DELAY);
|
||||
display.showNumberDec(1, false); // Expect: ___1
|
||||
delay(TEST_DELAY);
|
||||
display.showNumberDec(1, true); // Expect: 0001
|
||||
delay(TEST_DELAY);
|
||||
display.showNumberDec(301, false); // Expect: _301
|
||||
delay(TEST_DELAY);
|
||||
display.showNumberDec(301, true); // Expect: 0301
|
||||
delay(TEST_DELAY);
|
||||
display.clear();
|
||||
display.showNumberDec(14, false, 2, 1); // Expect: _14_
|
||||
delay(TEST_DELAY);
|
||||
display.clear();
|
||||
display.showNumberDec(4, true, 2, 2); // Expect: __04
|
||||
delay(TEST_DELAY);
|
||||
display.showNumberDec(-1, false); // Expect: __-1
|
||||
delay(TEST_DELAY);
|
||||
display.showNumberDec(-12); // Expect: _-12
|
||||
delay(TEST_DELAY);
|
||||
display.showNumberDec(-999); // Expect: -999
|
||||
delay(TEST_DELAY);
|
||||
display.clear();
|
||||
display.showNumberDec(-5, false, 3, 0); // Expect: _-5_
|
||||
delay(TEST_DELAY);
|
||||
display.showNumberHexEx(0xf1af); // Expect: f1Af
|
||||
delay(TEST_DELAY);
|
||||
display.showNumberHexEx(0x2c); // Expect: __2C
|
||||
delay(TEST_DELAY);
|
||||
display.showNumberHexEx(0xd1, 0, true); // Expect: 00d1
|
||||
delay(TEST_DELAY);
|
||||
display.clear();
|
||||
display.showNumberHexEx(0xd1, 0, true, 2); // Expect: d1__
|
||||
delay(TEST_DELAY);
|
||||
|
||||
// Run through all the dots
|
||||
for(k=0; k <= 4; k++) {
|
||||
display.showNumberDecEx(0, (0x80 >> k), true);
|
||||
delay(TEST_DELAY);
|
||||
}
|
||||
|
||||
// Brightness Test
|
||||
for(k = 0; k < 4; k++)
|
||||
data[k] = 0xff;
|
||||
for(k = 0; k < 7; k++) {
|
||||
display.setBrightness(k);
|
||||
display.setSegments(data);
|
||||
delay(TEST_DELAY);
|
||||
}
|
||||
|
||||
// On/Off test
|
||||
for(k = 0; k < 4; k++) {
|
||||
display.setBrightness(7, false); // Turn off
|
||||
display.setSegments(data);
|
||||
delay(TEST_DELAY);
|
||||
display.setBrightness(7, true); // Turn on
|
||||
display.setSegments(data);
|
||||
delay(TEST_DELAY);
|
||||
}
|
||||
|
||||
|
||||
// Done!
|
||||
display.setSegments(SEG_DONE);
|
||||
|
||||
while(1);
|
||||
}
|
||||
31
arduino-cli/libraries/TM1637-master/keywords.txt
Normal file
31
arduino-cli/libraries/TM1637-master/keywords.txt
Normal file
@@ -0,0 +1,31 @@
|
||||
#######################################
|
||||
# Datatypes (KEYWORD1)
|
||||
#######################################
|
||||
|
||||
TM1637Display KEYWORD1
|
||||
|
||||
#######################################
|
||||
# Methods and Functions (KEYWORD2)
|
||||
#######################################
|
||||
|
||||
setBrightness KEYWORD2
|
||||
setSegments KEYWORD2
|
||||
clear KEYWORD2
|
||||
showNumberDec KEYWORD2
|
||||
showNumberDecEx KEYWORD2
|
||||
showNumberHexEx KEYWORD2
|
||||
encodeDigit KEYWORD2
|
||||
|
||||
#######################################
|
||||
# Constants (LITERAL1)
|
||||
#######################################
|
||||
|
||||
SEG_A LITERAL1
|
||||
SEG_B LITERAL1
|
||||
SEG_C LITERAL1
|
||||
SEG_D LITERAL1
|
||||
SEG_E LITERAL1
|
||||
SEG_F LITERAL1
|
||||
SEG_G LITERAL1
|
||||
SEG_DP LITERAL1
|
||||
|
||||
14
arduino-cli/libraries/TM1637-master/library.json
Normal file
14
arduino-cli/libraries/TM1637-master/library.json
Normal file
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"name": "TM1637",
|
||||
"keywords": "LED, TM1637",
|
||||
"description": "Arduino library for TM1637 (LED Driver)",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/avishorp/TM1637.git"
|
||||
},
|
||||
"frameworks": "arduino",
|
||||
"platforms": [
|
||||
"atmelavr",
|
||||
"espressif"
|
||||
]
|
||||
}
|
||||
11
arduino-cli/libraries/TM1637-master/library.properties
Normal file
11
arduino-cli/libraries/TM1637-master/library.properties
Normal file
@@ -0,0 +1,11 @@
|
||||
name=TM1637
|
||||
version=1.2.0
|
||||
author=Avishay Orpaz <avishorp@gmail.com>
|
||||
maintainer=Avishay Orpaz <avishorp@gmail.com>
|
||||
sentence=Driver for 4 digit 7-segment display modules, based on the TM1637 chip.
|
||||
paragraph=These chips can be found in cheap display modules. They communicate with the processor in I2C-like protocol. The implementation is pure software emulation and doesn't make use of any special hardware (other than GPIO pins). It is assumed that pull-up resistors are present (usually integrated in the display module).
|
||||
category=Display
|
||||
url=https://github.com/avishorp/TM1637
|
||||
architectures=*
|
||||
includes=TM1637Display.h
|
||||
|
||||
28
arduino-cli/libraries/TM1637-master/platformio.ini
Normal file
28
arduino-cli/libraries/TM1637-master/platformio.ini
Normal file
@@ -0,0 +1,28 @@
|
||||
#
|
||||
# Project Configuration File
|
||||
#
|
||||
# A detailed documentation with the EXAMPLES is located here:
|
||||
# http://docs.platformio.org/en/latest/projectconf.html
|
||||
#
|
||||
|
||||
# A sign `#` at the beginning of the line indicates a comment
|
||||
# Comment lines are ignored.
|
||||
|
||||
# Simple and base environment
|
||||
# [env:mybaseenv]
|
||||
# platform = %INSTALLED_PLATFORM_NAME_HERE%
|
||||
# framework =
|
||||
# board =
|
||||
#
|
||||
# Automatic targets - enable auto-uploading
|
||||
# targets = upload
|
||||
|
||||
[env:nodemcuv2]
|
||||
platform = espressif
|
||||
framework = arduino
|
||||
board = nodemcuv2
|
||||
|
||||
[env:ethernet]
|
||||
platform = atmelavr
|
||||
framework = arduino
|
||||
board = ethernet
|
||||
13
arduino-cli/libraries/TM1637-master/release_notes.md
Normal file
13
arduino-cli/libraries/TM1637-master/release_notes.md
Normal file
@@ -0,0 +1,13 @@
|
||||
- V1.2.0
|
||||
* Add support for negative numbers
|
||||
* Add support for hexadeciaml number
|
||||
* Bump default bit delay to 100us, make it adjustable
|
||||
* Add Arduino library metadata
|
||||
|
||||
- V1.1.0
|
||||
* Add support for decimal points/colon
|
||||
* Minor fixes
|
||||
|
||||
- V1.0.0
|
||||
* Initial release
|
||||
|
||||
Reference in New Issue
Block a user