Skip to content

Commit 1b088bd

Browse files
authored
First version released
1 parent 10c0299 commit 1b088bd

File tree

5 files changed

+263
-0
lines changed

5 files changed

+263
-0
lines changed
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
2+
/* Include DigitLedDisplay Library */
3+
#include "DigitLedDisplay.h"
4+
5+
/* Arduino Pin to Display Pin
6+
7 to DIN,
7+
6 to CS,
8+
5 to CLK */
9+
DigitLedDisplay ld = DigitLedDisplay(7, 5, 6);
10+
11+
void setup() {
12+
13+
/* Set the brightness min:1, max:15 */
14+
ld.setBright(10);
15+
16+
/* Set the digit count */
17+
ld.setDigitLimit(8);
18+
19+
}
20+
21+
void loop() {
22+
23+
/* Prints data to the display */
24+
ld.printDigit(12345678);
25+
delay(500);
26+
ld.clear();
27+
28+
ld.printDigit(22222222);
29+
delay(500);
30+
ld.clear();
31+
32+
ld.printDigit(44444444);
33+
delay(500);
34+
ld.clear();
35+
36+
for (int i = 0; i < 100; i++) {
37+
ld.printDigit(i);
38+
39+
/* Start From Digit 4 */
40+
ld.printDigit(i, 4);
41+
delay(50);
42+
}
43+
44+
for (int i = 0; i <= 10; i++) {
45+
/* Display off */
46+
ld.off();
47+
delay(150);
48+
49+
/* Display on */
50+
ld.on();
51+
delay(150);
52+
}
53+
54+
/* Clear all display value */
55+
ld.clear();
56+
delay(500);
57+
58+
for (long i = 0; i < 100; i++) {
59+
ld.printDigit(i);
60+
delay(25);
61+
}
62+
63+
for (int i = 0; i <= 20; i++) {
64+
/* Select Digit 5 and write B01100011 */
65+
ld.write(5, B01100011);
66+
delay(200);
67+
68+
/* Select Digit 5 and write B00011101 */
69+
ld.write(5, B00011101);
70+
delay(200);
71+
}
72+
73+
/* Clear all display value */
74+
ld.clear();
75+
delay(500);
76+
77+
}

keywords.txt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#######################################
2+
# Syntax Coloring Map For DigitLedDisplay
3+
#######################################
4+
5+
#######################################
6+
# Datatypes (KEYWORD1)
7+
#######################################
8+
9+
BgrMax7seg KEYWORD1
10+
11+
#######################################
12+
# Methods and Functions (KEYWORD2)
13+
#######################################
14+
15+
clear KEYWORD2
16+
setBright KEYWORD2
17+
setDigitLimit KEYWORD2
18+
on KEYWORD2
19+
off KEYWORD2
20+
printDigit KEYWORD2
21+
write KEYWORD2
22+
23+
#######################################
24+
# Constants (LITERAL1)
25+
#######################################

library.properties

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
name=ESP8266-HW-SPI-MAX7219-7seg
2+
version=2.0.0
3+
author=Buger - based on Ozhan Duran <[email protected]>
4+
maintainer=Buger
5+
sentence=Multi MAX7219 7-Segment LED Display HW SPI Lib
6+
paragraph=Librery to use 1 or more MAX7219 7segment modules with ESP8266 over HW SPI
7+
category=Display
8+
url=http://buger.dread.cz
9+
architectures=*
10+
includes=esp8266-hw-spi-max7219-7seg.h
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
#include "esp8266-hw-spi-max7219-7seg.h"
2+
#include <SPI.h>
3+
4+
5+
#define DECODEMODE_ADDR 9
6+
#define BRIGHTNESS_ADDR 10
7+
#define SCANLIMIT_ADDR 11
8+
#define SHUTDOWN_ADDR 12
9+
#define DISPLAYTEST_ADDR 15
10+
#define NOOP_ADDR 0
11+
12+
13+
// init HW SPI
14+
BgrMax7seg::BgrMax7seg(uint32_t spiFreq, int csPin, int dispAmount) {
15+
CS_PIN = csPin;
16+
_dispAmount = dispAmount;
17+
pinMode(CS_PIN, OUTPUT);
18+
digitalWrite(CS_PIN, HIGH);
19+
SPI.begin();
20+
SPI.beginTransaction(SPISettings(spiFreq, MSBFIRST, SPI_MODE0));
21+
}
22+
23+
void BgrMax7seg::setBright(int brightness, int module) { // set brightness
24+
if (brightness>=0 && brightness<16)
25+
write(BRIGHTNESS_ADDR, brightness, module);
26+
}
27+
28+
void BgrMax7seg::init() { //init all modules with scanlimit, TODO: remove scanlimit at all
29+
write(DISPLAYTEST_ADDR, 0, ALL_MODULES); //turn off display test on all
30+
write(SCANLIMIT_ADDR, 7, ALL_MODULES); //sanlimit to all 8 digits (=7)
31+
write(DECODEMODE_ADDR, 0, ALL_MODULES); //turn off decode mode
32+
clear(ALL_MODULES); //clear all modules
33+
write(SHUTDOWN_ADDR, 1, ALL_MODULES); //turn all modules on
34+
}
35+
36+
void BgrMax7seg::on(int module) {
37+
write(SHUTDOWN_ADDR, 0x01, module);
38+
}
39+
40+
void BgrMax7seg::off(int module) {
41+
write(SHUTDOWN_ADDR, 0x00, module);
42+
}
43+
44+
void BgrMax7seg::clear(int module) {
45+
for (int i = 1; i <=8; i++) {
46+
write(i, B00000000, module);
47+
}
48+
}
49+
50+
void BgrMax7seg::table(byte address, int val, bool point, int module) {
51+
byte tableValue;
52+
tableValue = pgm_read_byte_near(segTable + val);
53+
if (point) {
54+
tableValue += 128; //decimal point
55+
}
56+
write(address, tableValue, module);
57+
}
58+
59+
void BgrMax7seg::write(volatile byte address, volatile byte data, volatile int module) { //when module == 0 send data to all of them
60+
digitalWrite(CS_PIN, LOW);
61+
for (int i = _dispAmount; i >= 1; i--) {
62+
if ((module == 0) or (module == i)) {
63+
SPI.transfer(address);
64+
SPI.transfer(data);
65+
} else {
66+
SPI.transfer(NOOP_ADDR);
67+
SPI.transfer(NOOP_ADDR);
68+
}
69+
}
70+
digitalWrite(CS_PIN, HIGH);
71+
}
72+
73+
void BgrMax7seg::print(String figure, int module) {
74+
figure.toUpperCase(); //we know only upperacase chars
75+
bool point = false;
76+
int len = figure.length();
77+
int position = len - 1; //string are indexed from 0 => -1 and we start from the end
78+
79+
for(int i = 1; i <= 8; i++) { //
80+
if (position >= 0) {
81+
// we are not outside of the string
82+
if (figure[position] == '.') {
83+
if (position > 0) {
84+
position--;
85+
point = true;
86+
}
87+
} else { //no point
88+
point = false;
89+
}
90+
if (figure[position] == ' ') { //space is not in table
91+
write(i, point * 128, module);
92+
} else { //search the table
93+
int parseInt = figure[position] - '-'; // first character of the segTable needs to be here
94+
table(i, parseInt, point, module);
95+
}
96+
position--;
97+
} else {
98+
// will print space
99+
write(i, 0, module);
100+
}
101+
102+
}
103+
}

src/esp8266-hw-spi-max7219-7seg.h

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#ifndef esp8266-hw-spi-max7219-7seg_h
2+
#define esp8266-hw-spi-max7219-7seg_h
3+
4+
#if (ARDUINO >= 100)
5+
#include <Arduino.h>
6+
#else
7+
#include <WProgram.h>
8+
#endif
9+
10+
#define ALL_MODULES 0 //use as module number to send to all
11+
12+
const static byte segTable [] PROGMEM = { // starting from 0
13+
1, // -
14+
128, // .
15+
0, // /
16+
126, // 0
17+
48, // 1
18+
109, // 2
19+
121, // 3
20+
51, // 4
21+
91, // 5
22+
95, // 6
23+
112, // 7
24+
127, // 8
25+
123, // 9
26+
0, 0, 0, 0, 0, 0, 0, // : ; < = > ? @ - will not display these
27+
119, 31, 78, 61, 79, 71, 95, 23, 48, 60, 87, 14, 84, 21, 126, 103, 115, 5, 91, 15, 62, 62, 42, 55, 59, 109 // A .. Z
28+
};
29+
30+
class BgrMax7seg
31+
{
32+
private:
33+
int CS_PIN;
34+
int _digitLimit;
35+
int _dispAmount;
36+
void table(byte address, int val, bool point, int module);
37+
public:
38+
BgrMax7seg(uint32_t spiFreq, int csPin, int dispAmount = 1); //dispAmount = number of connected modules
39+
void setBright(int brightness, int module = 1);
40+
void init();
41+
void print(String figure, int module = 1);
42+
void write(byte address, byte data, int module = 1);
43+
void clear(int module = 1);
44+
void on(int module = 1);
45+
void off(int module = 1);
46+
};
47+
48+
#endif //esp8266-hw-spi-max7219-7seg.h

0 commit comments

Comments
 (0)