Skip to content

Commit 34218c9

Browse files
committed
Add comments
Comments have been added to the following sketches: - SineWave.ino - DisplaySingleFrame.ino - GameOfLife.ino - LivePreview.ino - MatrixFrameBuffer.ino - PlayAnimation.ino
1 parent f19b922 commit 34218c9

File tree

6 files changed

+114
-24
lines changed

6 files changed

+114
-24
lines changed
Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,30 @@
1-
#include "analogWave.h"
1+
/*
2+
SineWave
23
3-
analogWave wave(DAC);
4+
Generates a pre-generated sawtooth-waveform.
5+
6+
See the full documentatio here:
7+
https://docs.arduino.cc/tutorials/uno-r4-wifi/dac
8+
*/
9+
10+
#include "analogWave.h" // Include the library for analog waveform generation
11+
12+
analogWave wave(DAC); // Create an instance of the analogWave class, using the DAC pin
413

514
int freq = 10; // in hertz, change accordingly
615

716
void setup() {
8-
Serial.begin(115200);
9-
wave.sine(freq);
17+
Serial.begin(115200); // Initialize serial communication at a baud rate of 115200
18+
wave.sine(freq); // Generate a sine wave with the initial frequency
1019
}
1120

1221
void loop() {
22+
// Read an analog value from pin A5 and map it to a frequency range
1323
freq = map(analogRead(A5), 0, 1024, 0, 10000);
24+
25+
// Print the updated frequency to the serial monitor
1426
Serial.println("Frequency is now " + String(freq) + " hz");
15-
wave.freq(freq);
16-
delay(1000);
27+
28+
wave.freq(freq); // Set the frequency of the waveform generator to the updated value
29+
delay(1000); // Delay for one second before repeating
1730
}
Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,39 @@
1-
#include "Arduino_LED_Matrix.h"
2-
#include "frames.h"
1+
/*
2+
Single Frame
33
4-
ArduinoLEDMatrix matrix;
4+
Displays single frames using matrix.loadFrame
5+
6+
See the full documentation here:
7+
https://docs.arduino.cc/tutorials/uno-r4-wifi/led-matrix
8+
*/
9+
10+
#include "Arduino_LED_Matrix.h" // Include the library for controlling LED matrix
11+
#include "frames.h" // Include a header file containing frame data
12+
13+
ArduinoLEDMatrix matrix; // Create an instance of the ArduinoLEDMatrix class
514

615
void setup() {
7-
Serial.begin(115200);
8-
matrix.begin();
9-
}
16+
Serial.begin(115200); // Initialize serial communication at a baud rate of 115200
17+
matrix.begin(); // Initialize the LED matrix
18+
}
1019

1120
void loop() {
21+
// Load and display the "chip" frame on the LED matrix
1222
matrix.loadFrame(chip);
13-
delay(500);
23+
delay(500); // Pause for 500 milliseconds (half a second)
24+
25+
// Load and display the "happy" frame on the LED matrix
1426
matrix.loadFrame(danger);
15-
delay(500);
27+
delay(500); // Pause for 500 milliseconds (half a second)
28+
29+
// Load and display the "happy" frame on the LED matrix
1630
matrix.loadFrame(happy);
17-
delay(500);
31+
delay(500); // Pause for 500 milliseconds (half a second)
32+
33+
// Load and display the "heart" frame on the LED matrix
1834
matrix.loadFrame(heart);
19-
delay(500);
35+
delay(500); // Pause for 500 milliseconds (half a second)
36+
37+
// Print the current value of millis() to the serial monitor
2038
Serial.println(millis());
2139
}

libraries/Arduino_LED_Matrix/examples/GameOfLife/GameOfLife.ino

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
/*
2+
Game Of Life
3+
4+
The Game of Life, also known simply as Life, is a cellular automaton devised
5+
by the British mathematician John Horton Conway in 1970. It is a zero-player game,
6+
meaning that its evolution is determined by its initial state, requiring no further
7+
input.
8+
29
Example developed starting from Toby Oxborrow's sketch
310
https://github.com/tobyoxborrow/gameoflife-arduino/blob/master/GameOfLife.ino
11+
12+
See the full documentation here:
13+
https://docs.arduino.cc/tutorials/uno-r4-wifi/led-matrix
414
*/
515

616
#include "Arduino_LED_Matrix.h"

libraries/Arduino_LED_Matrix/examples/LivePreview/LivePreview.ino

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,34 @@
55
The LED Matrix editor is part of Arduino Labs (https://labs.arduino.cc/), and is therefore considered experimental software.
66
77
Don't forget to close any serial monitor already opened.
8+
9+
See the full documentation here:
10+
https://docs.arduino.cc/tutorials/uno-r4-wifi/led-matrix
811
*/
912

10-
#include "Arduino_LED_Matrix.h"
13+
#include "Arduino_LED_Matrix.h" // Include the library for controlling LED matrix
1114

12-
ArduinoLEDMatrix matrix;
15+
ArduinoLEDMatrix matrix; // Create an instance of the ArduinoLEDMatrix class
1316

1417
void setup() {
15-
Serial.begin(115200);
16-
matrix.begin();
18+
Serial.begin(115200); // Initialize serial communication at a baud rate of 115200
19+
matrix.begin(); // Initialize the LED matrix
1720
}
1821

22+
// Define an array to hold pixel data for a single frame (4 pixels)
1923
uint32_t frame[] = {
2024
0, 0, 0, 0xFFFF
2125
};
2226

2327
void loop() {
28+
// Check if there are at least 12 bytes available in the serial buffer
2429
if(Serial.available() >= 12){
30+
// Read 4 bytes from the serial buffer and compose them into a 32-bit value for each element in the frame
2531
frame[0] = Serial.read() | Serial.read() << 8 | Serial.read() << 16 | Serial.read() << 24;
2632
frame[1] = Serial.read() | Serial.read() << 8 | Serial.read() << 16 | Serial.read() << 24;
2733
frame[2] = Serial.read() | Serial.read() << 8 | Serial.read() << 16 | Serial.read() << 24;
34+
35+
// Load and display the received frame data on the LED matrix
2836
matrix.loadFrame(frame);
2937
}
30-
}
31-
38+
}

libraries/Arduino_LED_Matrix/examples/MatrixFrameBuffer/MatrixFrameBuffer.ino

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,21 @@
1+
/*
2+
Matrix Frame Buffer
3+
4+
This Arduino sketch demonstrates the creation and manipulation of
5+
a frame buffer for the LED matrix. The frame buffer is used to control
6+
the lighting of individual LEDs on the matrix, turning them randomly on and off.
7+
8+
See the full documentation here:
9+
https://docs.arduino.cc/tutorials/uno-r4-wifi/led-matrix
10+
*/
11+
12+
// Include the Arduino_LED_Matrix library
113
#include "Arduino_LED_Matrix.h"
14+
15+
// Creating an instance of the ArduinoLEDMatrix class
216
ArduinoLEDMatrix matrix;
317

18+
// Defining the frame array for the LED matrix with pixel values
419
uint8_t frame[8][12] = {
520
{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
621
{ 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0 },
@@ -12,26 +27,36 @@ uint8_t frame[8][12] = {
1227
{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }
1328
};
1429

30+
// Setting up time intervals and dimensions for the matrix
1531
unsigned long lastTickTime, lastGameTickTime;
1632
#define UPDATE_INTERVAL 100
1733
#define GAME_UPDATE_INTERVAL 66
1834

1935
#define ROWS 8
2036
#define COLUMNS 12
2137

38+
// Variables to track the current positions
2239
uint8_t pointX = 0, pointY = 0;
2340

2441
void setup() {
25-
// put your setup code here, to run once:
42+
// Initializing serial communication and delaying for setup
2643
Serial.begin(115200);
2744
delay(1500);
45+
46+
// Initializing the LED matrix
2847
matrix.begin();
48+
49+
// Initializing time tracking variables
2950
lastGameTickTime = lastTickTime = millis();
3051
}
3152

3253
void loop() {
54+
// Tracking the current time
3355
unsigned long msNow = millis();
56+
57+
// Updating the game logic with a fixed interval
3458
if (msNow - lastGameTickTime > GAME_UPDATE_INTERVAL) {
59+
// Incrementing pointX and handling wraparound
3560
pointX++;
3661
if (pointX >= COLUMNS) {
3762
pointX = 0;
@@ -40,14 +65,24 @@ void loop() {
4065
pointY = 0;
4166
}
4267
}
68+
69+
// Generating random positions and pixel value
4370
pointX = random(COLUMNS);
4471
pointY = random(ROWS);
4572
uint8_t pixelValue = random(2);
73+
74+
// Updating the frame with the new pixel value
4675
frame[pointY][pointX] = pixelValue;
76+
77+
// Updating the last game tick time
4778
lastGameTickTime = msNow;
4879
}
80+
81+
// Rendering the LED matrix with the current frame at a fixed interval
4982
if (msNow - lastTickTime > UPDATE_INTERVAL) {
5083
matrix.renderBitmap(frame, 8, 12);
84+
85+
// Updating the last rendering tick time
5186
lastTickTime = msNow;
5287
}
5388
}

libraries/Arduino_LED_Matrix/examples/PlayAnimation/PlayAnimation.ino

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
1+
/*
2+
Sketch shows animation defined in animation.h
3+
*/
4+
5+
//Include library and animation.h
6+
17
#include "Arduino_LED_Matrix.h"
28
#include "animation.h"
39

4-
ArduinoLEDMatrix matrix;
10+
// Create an instance of the ArduinoLEDMatrix class
11+
ArduinoLEDMatrix matrix;
512

613
void setup() {
714
Serial.begin(115200);

0 commit comments

Comments
 (0)