https://github.com/niklauslee/tm1637
Kaluma library for 7-segment LED Display
https://github.com/niklauslee/tm1637
7-segment display kaluma led
Last synced: over 1 year ago
JSON representation
Kaluma library for 7-segment LED Display
- Host: GitHub
- URL: https://github.com/niklauslee/tm1637
- Owner: niklauslee
- License: mit
- Created: 2022-02-17T04:00:34.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2022-02-17T04:56:45.000Z (over 4 years ago)
- Last Synced: 2025-01-21T17:30:36.903Z (over 1 year ago)
- Topics: 7-segment, display, kaluma, led
- Language: JavaScript
- Homepage:
- Size: 40 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# TM1637 (7-segment display)
Kaluma library for 7-segment LED Display
# Wiring
Here is a wiring example.
| Raspberry Pi Pico | TM1637 |
| ----------------- | ------ |
| 3V3 | VCC |
| GND | GND |
| GP0 | CLK |
| GP1 | DIO |

# Install
```sh
npm install https://github.com/niklauslee/tm1637
```
# Usage
```javascript
const {TM1637} = require('tm1637');
const tm1637 = new TM1637(0, 1); // CLK=0, DIO=1
// Show "03:15"
tm1637.setDigit(0, TM1637.DIGIT[0]); // 0
tm1637.setDigit(1, TM1637.DIGIT[3] | TM1637.SEG_X); // 3:
tm1637.setDigit(2, TM1637.DIGIT[1]); // 1
tm1637.setDigit(3, TM1637.DIGIT[5]); // 5
delay(1000);
// Change brightness (0 ~ 7)
for (i = 0; i <= 7; i++) {
tm1637.setBrightness(i);
delay(500);
}
delay(1000);
// Display on and off (blinking)
for (i = 0; i < 10; i++) {
tm1637.off();
delay(100);
tm1637.on();
delay(100);
}
delay(1000);
// Show number from 0 to 500
for (i = 0; i <= 500; i++) {
tm1637.display(i);
}
delay(1000);
// Show "done"
tm1637.setDigit(0, TM1637.SEG_B | TM1637.SEG_C | TM1637.SEG_D | TM1637.SEG_E | TM1637.SEG_G); // d
tm1637.setDigit(1, TM1637.SEG_C | TM1637.SEG_D | TM1637.SEG_E | TM1637.SEG_G); // o
tm1637.setDigit(2, TM1637.SEG_C | TM1637.SEG_E | TM1637.SEG_G); // n
tm1637.setDigit(3, TM1637.SEG_A | TM1637.SEG_B | TM1637.SEG_D | TM1637.SEG_E | TM1637.SEG_F | TM1637.SEG_G); // e
```
# API
## Class: TM1637
A class encapulating TM1637 driver.
### new TM1637(clkPin, dioPin[, length[, brightness]])
Create an instance of TM1637 class.
- **`clkPin`** `` Pin number for CLK.
- **`dioPin`** `` Pin number for DIO.
- **`length`** `` Number of digits. Default: `4`.
- **`brightness`** `` Level of brightness (0~7). Default: `7`.
### tm1637.clear()
Clear all digits.
### tm1637.on()
Turn on the display.
### tm1637.off()
Turn off the display.
### tm1637.setBrightness(brightness)
Set the brightness of the display.
- **`brightness`** `` Level of brightness (0~7).
### tm1637.setDigit(pos, data)
Set a digit with the data.
- **`pos`** `` Position to set digit data.
- **`data`** `` 7-segment data for the digit.
```
7-SEGMENT
A
---
F | | B
-G-
E | | C
--- . X
D
```
### tm1637.display(value)
Show the number value on the display.
- **`value`** `` A number to display.
### TM1637.SEG_A
Bit for the segment A. (`0x01`)
- ``
### TM1637.SEG_B
Bit for the segment B. (`0x02`)
- ``
### TM1637.SEG_C
Bit for the segment C. (`0x04`)
- ``
### TM1637.SEG_D
Bit for the segment D. (`0x08`)
- ``
### TM1637.SEG_E
Bit for the segment E. (`0x10`)
- ``
### TM1637.SEG_F
Bit for the segment F. (`0x20`)
- ``
### TM1637.SEG_G
Bit for the segment G. (`0x40`)
- ``
### TM1637.SEG_X
Bit for the segment X (Dot or Colon). (`0x80`)
- ``
### TM1637.DIGIT
An array of 7-segment data for number digits from 0 to 9.
- `Array`