Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit b42786d

Browse files
Merge pull request #112 from facchinm/led_arduinographics
led_matrix: add support for text using ArduinoGraphics APIs
2 parents b9af82f + 941a7d0 commit b42786d

File tree

2 files changed

+89
-4
lines changed

2 files changed

+89
-4
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// To use ArduinoGraphics APIs, please include BEFORE Arduino_LED_Matrix
2+
#include "ArduinoGraphics.h"
3+
#include "Arduino_LED_Matrix.h"
4+
5+
ArduinoLEDMatrix matrix;
6+
7+
void setup() {
8+
Serial.begin(115200);
9+
matrix.begin();
10+
11+
matrix.beginDraw();
12+
matrix.stroke(0xFFFFFFFF);
13+
// add some static text
14+
// will only show "UNO" (not enough space on the display)
15+
const char text[] = "UNO r4";
16+
matrix.textFont(Font_4x6);
17+
matrix.beginText(0, 1, 0xFFFFFF);
18+
matrix.println(text);
19+
matrix.endText();
20+
21+
matrix.endDraw();
22+
23+
delay(2000);
24+
}
25+
26+
void loop() {
27+
28+
// Make it scroll!
29+
matrix.beginDraw();
30+
31+
matrix.stroke(0xFFFFFFFF);
32+
matrix.textScrollSpeed(50);
33+
34+
// add the text
35+
const char text[] = " Scrolling text! ";
36+
matrix.textFont(Font_5x7);
37+
matrix.beginText(0, 1, 0xFFFFFF);
38+
matrix.println(text);
39+
matrix.endText(SCROLL_LEFT);
40+
41+
matrix.endDraw();
42+
}

‎libraries/Arduino_LED_Matrix/src/Arduino_LED_Matrix.h‎

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33

44
#define NUM_LEDS 96
55

6+
#if __has_include("ArduinoGraphics.h")
7+
#include <ArduinoGraphics.h>
8+
#define MATRIX_WITH_ARDUINOGRAPHICS
9+
#endif
10+
611
static const int pin_zero_index = 28;
712

813
static const uint8_t pins[][2] = {
@@ -138,10 +143,18 @@ static uint32_t reverse(uint32_t x)
138143

139144
static uint8_t __attribute__((aligned)) framebuffer[NUM_LEDS / 8];
140145

141-
class ArduinoLEDMatrix {
146+
class ArduinoLEDMatrix
147+
#ifdef MATRIX_WITH_ARDUINOGRAPHICS
148+
: public ArduinoGraphics
149+
#endif
150+
{
142151

143152
public:
144-
ArduinoLEDMatrix() {}
153+
ArduinoLEDMatrix()
154+
#ifdef MATRIX_WITH_ARDUINOGRAPHICS
155+
: ArduinoGraphics(canvasWidth, canvasHeight)
156+
#endif
157+
{}
145158
// TODO: find a better name
146159
// autoscroll will be slower than calling next() at precise times
147160
void autoscroll(uint32_t interval_ms) {
@@ -153,7 +166,7 @@ class ArduinoLEDMatrix {
153166
void off(size_t pin) {
154167
turnLed(pin, false);
155168
}
156-
void begin() {
169+
int begin() {
157170
uint8_t type;
158171
uint8_t ch = FspTimer::get_available_timer(type);
159172
// TODO: avoid passing "this" argument to remove autoscroll
@@ -231,7 +244,37 @@ class ArduinoLEDMatrix {
231244
void setCallback(voidFuncPtr callBack){
232245
_callBack = callBack;
233246
}
234-
247+
248+
#ifdef MATRIX_WITH_ARDUINOGRAPHICS
249+
virtual void set(int x, int y, uint8_t r, uint8_t g, uint8_t b) {
250+
if (y >= canvasHeight || x >= canvasWidth) {
251+
return;
252+
}
253+
// the r parameter is (mis)used to set the character to draw with
254+
_canvasBuffer[y][x] = (r | g | b) > 0 ? 1 : 0;
255+
}
256+
257+
void endText(int scrollDirection = NO_SCROLL) {
258+
ArduinoGraphics::endText(scrollDirection);
259+
renderBitmap(_canvasBuffer, canvasHeight, canvasWidth);
260+
}
261+
262+
// display the drawing
263+
void endDraw() {
264+
ArduinoGraphics::endDraw();
265+
// clear first line (no idea why it gets filled with random bits, probably some math not working fine for super small displays)
266+
for (int i = 0; i < canvasWidth; i++) {
267+
_canvasBuffer[0][i] = 0;
268+
}
269+
renderBitmap(_canvasBuffer, canvasHeight, canvasWidth);
270+
}
271+
272+
private:
273+
static const byte canvasWidth = 12;
274+
static const byte canvasHeight = 8;
275+
uint8_t _canvasBuffer[canvasHeight][canvasWidth] = {{0}};
276+
#endif
277+
235278
private:
236279
int _currentFrame = 0;
237280
uint32_t _frameHolder[3];

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /