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 c1280ca

Browse files
Merge pull request #1133 from arduino/jacobhylen/unor4-led-matrix-update
UNO R4 WiFi LED Matrix guide update
2 parents 0c992e1 + 9c58534 commit c1280ca

File tree

1 file changed

+18
-11
lines changed
  • content/hardware/02.hero/boards/uno-r4-wifi/tutorials/led-matrix

1 file changed

+18
-11
lines changed

‎content/hardware/02.hero/boards/uno-r4-wifi/tutorials/led-matrix/led-matrix.md‎

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ software:
1414
---
1515

1616
The **Arduino UNO R4 WiFi** comes with a built in 12x8 LED Matrix, that is available to be programmed to display graphics, animations, act as an interface, or even play games on.
17-
1817
## Goals
1918

2019
The matrix and its API are developed to be programmed in a few different ways, each suited for different applications. This guide will walk you through the basic concepts for programming the LED matrix, and get you started with creating your own animations, while highlighting two different ways of handling the LEDs to create animations and images. This makes it easier for you to decide what method fits your needs best!
@@ -68,7 +67,7 @@ A frame is what we call the "image" that is displayed at any given moment on the
6867

6968
How this frame is created can vary quite a lot, and you can choose whatever way is the easiest for your application, but most of the time you'll be creating an array that holds the frame in three 32-bit integers. A frame like this is difficult for a person to interpret, but it is efficient and therefore the way to go if you're making animations or graphics to display the states of a program or interfaces. You can create frames and animations such as this one by [this browser tool](#animation-generation) developed by Arduino. Such a frame may look similar to this:
7069

71-
```
70+
```arduino
7271
const uint32_t heart[] = {
7372
0x3184a444,
7473
0x44042081,
@@ -77,7 +76,7 @@ const uint32_t heart[] = {
7776
```
7877

7978
Now if you've got several different frames, you can load and display them like this:
80-
```
79+
```arduino
8180
const uint32_t happy[] = {
8281
0x19819,
8382
0x80000001,
@@ -90,16 +89,17 @@ const uint32_t heart[] = {
9089
0x100a0040
9190
};
9291
93-
matrix.loadFrame(happy);
92+
matrix.loadFrame(happy);
9493
delay(500);
94+
9595
matrix.loadFrame(heart);
9696
delay(500);
9797
```
9898

9999

100100
You may also represent your frame with an array of individual bits, where each pixel is represented by a bit, and can be accessed by its row and column (this way being a good choice if you need to generate frames from within a sketch, for instance if you are making a game). This `frame` array contains a representation of each pixel in the matrix laid out in the same 12x8 grid.
101101

102-
```
102+
```arduino
103103
uint8_t frame[8][12] = {
104104
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
105105
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
@@ -113,8 +113,9 @@ uint8_t frame[8][12] = {
113113
114114
```
115115
To target an individual pixel you select its address and change the value, remember that you'll need to start counting at 0. So, the following line will target the third pixel from the left and the second from the top, then turn it on:
116-
```
116+
```arduino
117117
frame[2][1] = 1;
118+
118119
matrix.renderBitmap(frame, 8, 12);
119120
```
120121

@@ -124,9 +125,11 @@ Let's apply these concepts, with two basic sketches that display different frame
124125

125126
Here's a sketch that will first load a smiley face on your matrix, and then change it to a heart.
126127

127-
```
128+
```arduino
128129
#include "Arduino_LED_Matrix.h"
130+
129131
ArduinoLEDMatrix matrix;
132+
130133
void setup() {
131134
Serial.begin(115200);
132135
matrix.begin();
@@ -146,6 +149,7 @@ const uint32_t heart[] = {
146149
void loop(){
147150
matrix.loadFrame(happy);
148151
delay(500);
152+
149153
matrix.loadFrame(heart);
150154
delay(500);
151155
}
@@ -155,9 +159,11 @@ The sketch is pretty simple, and yet the outcome is very expressive and can help
155159

156160
Now let's change approach and create a bitmap that we change in runtime. This sketch includes several functions that each draw part of a face, and then winks the left eye by turning off certain pixels.
157161

158-
```
162+
```arduino
159163
#include "Arduino_LED_Matrix.h"
164+
160165
ArduinoLEDMatrix matrix;
166+
161167
void setup() {
162168
Serial.begin(115200);
163169
matrix.begin();
@@ -175,7 +181,7 @@ uint8_t frame[8][12] = {
175181
};
176182
177183
void leftEye(){
178-
//Left eye
184+
//Left eye
179185
frame[1][3] = 1;
180186
frame[1][4] = 1;
181187
frame[2][3] = 1;
@@ -191,15 +197,15 @@ void wink(){
191197
}
192198
193199
void rightEye(){
194-
//Right eye
200+
//Right eye
195201
frame[1][8] = 1;
196202
frame[1][9] = 1;
197203
frame[2][8] = 1;
198204
frame[2][9] = 1;
199205
}
200206
201207
void mouth(){
202-
//Mouth
208+
//Mouth
203209
frame[5][3] = 1;
204210
frame[5][9] = 1;
205211
frame[6][3] = 1;
@@ -220,6 +226,7 @@ matrix.renderBitmap(frame, 8, 12);
220226
221227
delay(1000);
222228
wink();
229+
223230
matrix.renderBitmap(frame, 8, 12);
224231
delay(1000);
225232
}

0 commit comments

Comments
(0)

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