Skip to content

Commit b4c25f7

Browse files
examples: add comments (#101)
1 parent c8c79e2 commit b4c25f7

File tree

31 files changed

+341
-116
lines changed

31 files changed

+341
-116
lines changed

libraries/AnalogWave/examples/DACEqualTemperedScale/DACEqualTemperedScale.ino

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
created 18 Dec 2018
2222
modified 3 Jul 2023
2323
by Tom Igoe
24+
25+
See the full documentation here:
26+
https://docs.arduino.cc/tutorials/uno-r4-wifi/dac
2427
*/
2528

2629
// include the AnalogWave library:

libraries/AnalogWave/examples/DACJacques/DACJacques.ino

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*
1+
/*
22
DAC Melody player
33
44
Generates a series of tones from MIDI note values
@@ -14,6 +14,9 @@ circuit:
1414
created 13 Feb 2017
1515
modified 3 Jul 2023
1616
by Tom Igoe
17+
18+
See the full documentation here:
19+
https://docs.arduino.cc/tutorials/uno-r4-wifi/dac
1720
*/
1821
#include "analogWave.h"
1922
analogWave wave(DAC);
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 documentation 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
}

libraries/Arduino_CAN/examples/CANRead/CANRead.ino

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
/*
2+
CANRead
3+
4+
Receive and read CAN Bus messages
5+
6+
See the full documentation here:
7+
https://docs.arduino.cc/tutorials/uno-r4-wifi/can
8+
*/
9+
110
/**************************************************************************************
211
* INCLUDE
312
**************************************************************************************/

libraries/Arduino_CAN/examples/CANWrite/CANWrite.ino

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
/*
2+
CANWrite
3+
4+
Write and send CAN Bus messages
5+
6+
See the full documentation here:
7+
https://docs.arduino.cc/tutorials/uno-r4-wifi/can
8+
*/
9+
110
/**************************************************************************************
211
* INCLUDE
312
**************************************************************************************/

libraries/Arduino_FreeRTOS/examples/FreeRTOS-Blink/FreeRTOS-Blink.ino

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
/*
2+
The code demonstrates the usage of FreeRTOS (Real-Time Operating System) to run concurrent tasks.
3+
4+
One task is responsible for running the loop() logic (in a thread-safe manner),
5+
while the other task blinks an LED using the built-in LED on non-Portenta boards or
6+
the RGB LED on the Portenta C33 board.
7+
*/
8+
19
/**************************************************************************************
210
* INCLUDE
311
**************************************************************************************/
Lines changed: 24 additions & 6 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
3+
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+
*/
39

4-
ArduinoLEDMatrix matrix;
10+
#include "Arduino_LED_Matrix.h" // Include the LED_Matrix library
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();
16+
Serial.begin(115200); // Initialize serial communication at a baud rate of 115200
17+
matrix.begin(); // Initialize the LED matrix
918
}
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 "danger" frame on the LED matrix
1426
matrix.loadFrame(danger);
1527
delay(500);
28+
29+
// Load and display the "happy" frame on the LED matrix
1630
matrix.loadFrame(happy);
1731
delay(500);
32+
33+
// Load and display the "heart" frame on the LED matrix
1834
matrix.loadFrame(heart);
1935
delay(500);
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: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
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

6-
#include "Arduino_LED_Matrix.h"
16+
#include "Arduino_LED_Matrix.h" // Include the LED_Matrix library
717

818
// grid dimensions. should not be larger than 8x8
919
#define MAX_Y 8

libraries/Arduino_LED_Matrix/examples/LivePreview/LivePreview.ino

Lines changed: 12 additions & 5 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 LED_Matrix library
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
}
3038
}
31-
Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,23 @@
1-
#include "Arduino_LED_Matrix.h"
2-
ArduinoLEDMatrix matrix;
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+
*/
311

12+
// Include the LED_Matrix library
13+
#include "Arduino_LED_Matrix.h"
14+
15+
// Create an instance of the ArduinoLEDMatrix class
16+
ArduinoLEDMatrix matrix;
17+
18+
// Define the frame array for the LED matrix with pixel values
419
uint8_t frame[8][12] = {
5-
{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
20+
{ 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 },
722
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
823
{ 0, 0, 0, 0, 0, 1, 1, 0, 0, 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+
// Set 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+
// Initialize serial communication and delaying for setup
2643
Serial.begin(115200);
2744
delay(1500);
45+
46+
// Initialize the LED matrix
2847
matrix.begin();
48+
49+
// Initialize time tracking variables
2950
lastGameTickTime = lastTickTime = millis();
3051
}
3152

3253
void loop() {
54+
// Track the current time
3355
unsigned long msNow = millis();
56+
57+
// Update the game logic with a fixed interval
3458
if (msNow - lastGameTickTime > GAME_UPDATE_INTERVAL) {
59+
// Increment 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+
// Generate random positions and pixel value
4370
pointX = random(COLUMNS);
4471
pointY = random(ROWS);
4572
uint8_t pixelValue = random(2);
73+
74+
// Update the frame with the new pixel value
4675
frame[pointY][pointX] = pixelValue;
76+
77+
// Update the last game tick time
4778
lastGameTickTime = msNow;
4879
}
80+
81+
// Render 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+
// Update the last rendering tick time
5186
lastTickTime = msNow;
5287
}
5388
}

libraries/Arduino_LED_Matrix/examples/MatrixIntro/MatrixIntro.ino

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
1212
created 26 Jun 2023
1313
by Martino Facchin
14+
15+
See the full documentation here:
16+
https://docs.arduino.cc/tutorials/uno-r4-wifi/led-matrix
1417
*/
1518

1619

libraries/Arduino_LED_Matrix/examples/PlayAnimation/PlayAnimation.ino

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
1-
#include "Arduino_LED_Matrix.h"
2-
#include "animation.h"
1+
/*
2+
Play Animation
33
4-
ArduinoLEDMatrix matrix;
4+
Sketch shows animation defined in animation.h
5+
6+
See the full documentation here:
7+
https://docs.arduino.cc/tutorials/uno-r4-wifi/led-matrix
8+
*/
9+
10+
11+
12+
#include "Arduino_LED_Matrix.h" //Include the LED_Matrix library
13+
#include "animation.h" //Include animation.h header file
14+
15+
// Create an instance of the ArduinoLEDMatrix class
16+
ArduinoLEDMatrix matrix;
517

618
void setup() {
719
Serial.begin(115200);

libraries/EEPROM/examples/eeprom_read/eeprom_read.ino

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
/*
2-
* EEPROM Read
3-
*
4-
* Reads the value of each byte of the EEPROM and prints it
5-
* to the computer.
6-
* This example code is in the public domain.
2+
EEPROM Read
3+
4+
Reads the value of each byte of the EEPROM and prints it
5+
to the computer.
6+
This example code is in the public domain.
7+
8+
See the full documentation here:
9+
https://docs.arduino.cc/tutorials/uno-r4-wifi/eeprom
710
*/
811

12+
// Include the EEPROM library
913
#include <EEPROM.h>
1014

1115
// start reading from the first byte (address 0) of the EEPROM

libraries/EEPROM/examples/eeprom_write/eeprom_write.ino

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
/*
2-
* EEPROM Write
3-
*
4-
* Stores values read from analog input 0 into the EEPROM.
5-
* These values will stay in the EEPROM when the board is
6-
* turned off and may be retrieved later by another sketch.
2+
EEPROM Write
3+
4+
Stores values read from analog input 0 into the EEPROM.
5+
These values will stay in the EEPROM when the board is
6+
turned off and may be retrieved later by another sketch.
7+
8+
See the full documentation here:
9+
https://docs.arduino.cc/tutorials/uno-r4-wifi/eeprom
710
*/
811

12+
// Include the EEPROM library
913
#include <EEPROM.h>
1014

1115
/** the current address in the EEPROM (i.e. which byte we're going to write to next) **/

libraries/RTC/examples/RTC_Alarm/RTC_Alarm.ino

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
/*
2+
* RTC_Alarm
3+
*
24
* This example demonstrates how to use the alarm functionality of the RTC
35
* (Real Time Clock) on the Portenta C33 and UNO R4 Minima / WiFi.
46
*
@@ -9,12 +11,16 @@
911
*
1012
* Note that the Portenta C33's LED is inverted and will be lit when
1113
* the state is 0 (LOW).
14+
*
15+
* Find the full UNO R4 WiFi RTC documentation here:
16+
* https://docs.arduino.cc/tutorials/uno-r4-wifi/rtc
1217
*/
1318

1419
unsigned long previousMillis = 0;
1520
const long interval = 1000;
1621
bool ledState = false;
1722

23+
// Include the RTC library
1824
#include "RTC.h"
1925

2026
void setup() {

0 commit comments

Comments
 (0)