The code is structured into several key sections: defining pin connections, setting up the Arduino board, the main loop for the heartbeat effect, and functions to control the LED matrix.
1. Pin Definitions:
led_row and led_col arrays define the pins connected to the rows and columns of the LED matrix, respectively.
2. LED Coordinates:
coords_1 array contains the coordinates for the first heart shape.
coords_2 array contains the coordinates for the second heart shape, which is used to create the new effect of lighting up all LEDs within the heart contour.
3. Setup Function:
Initializes all the row and column pins as outputs, setting the stage for controlling the LED matrix.
4. Loop Function:
The loop() function now includes an additional loop to handle the new effect. It iterates through the coords_1 array for the first heart shape, then reverses the direction for the second part of the heartbeat, and finally iterates through the coords_2 array to light up all LEDs within the heart contour.
5. Reset Function:
reset_all() turns off the entire LED matrix by setting all row pins low and all column pins high.
6. Display Function:
display() lights up a single LED at the specified coordinates.
display_all() lights up all LEDs within a specified row (y) from column x1 to column x2, effectively lighting up the area enclosed by the heart contour.
7. Speed Adjustment:
The delay() in the display() and display_all() functions adjust the speed of the heartbeat effect. This can be modified to make the effect faster or slower.
How It WorksWhen the Arduino board is powered and the code is executed, the loop() function continuously iterates through the code[] array, lighting up LEDs in a sequence that forms a heart shape. The forward and backward iteration through the array creates the effect of the heart "beating." The reset_all() function ensures that the matrix is cleared before each new heartbeat cycle, and the display() and display_all() functions manage the individual lighting of LEDs based on their coordinates.
Comments