Skip to content

Commit 2d29675

Browse files
5irivovw
andauthored
1_led_matrix: Game of Life example using LED matrix and removal of 4_switch_controlled_motor_normal and accordingly rearrange the rest of the folders (#172)
* 1_led_matrix: Game of Life example using LED matrix setup * 1_led_matrix: rename project target * create 1_led_matrix; remove 4_switch_motor_control_normal; update git accordingly; * simplify frame logic --------- Co-authored-by: atharva <62803658+vovw@users.noreply.github.com>
1 parent 0ddf6df commit 2d29675

51 files changed

Lines changed: 97 additions & 256 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/test-build-app.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
image: espressif/idf:release-v5.1
1111
strategy:
1212
matrix:
13-
test-apps: [1_led_matrix, 2_LSA, 3_MPU, 5_PWM, 6_line_following, 7_self_balancing]
13+
test-apps: [1_led_matrix, 2_LSA, 3_MPU, 4_PWM, 5_line_following, 6_self_balancing]
1414
steps:
1515
- name: Force Install GIT latest
1616
run: |

.gitmodules

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[submodule "components/sra-board-component"]
22
path = components/sra-board-component
33
url = https://github.com/SRA-VJTI/sra-board-component.git
4-
[submodule "8_self_balancing/components/websocket"]
5-
path = 7_self_balancing/components/websocket
4+
[submodule "6_self_balancing/components/websocket"]
5+
path = 6_self_balancing/components/websocket
66
url = https://github.com/Molorius/esp32-websocket.git

1_led_blink/README.md

Lines changed: 0 additions & 34 deletions
This file was deleted.

1_led_blink/main/main.c

Lines changed: 0 additions & 53 deletions
This file was deleted.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ cmake_minimum_required(VERSION 3.5)
44

55
set(EXTRA_COMPONENT_DIRS ../components)
66
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
7-
project(blink_bar_graph_led)
7+
project(led_matrix_game_of_life)

1_led_matrix/README.md

Lines changed: 16 additions & 0 deletions
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ set(COMPONENT_PRIV_REQUIRES )
55
set(COMPONENT_SRCS "main.c")
66
set(COMPONENT_ADD_INCLUDEDIRS "")
77

8-
register_component()
8+
register_component()

1_led_matrix/main/main.c

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#include <freertos/FreeRTOS.h>
2+
#include <freertos/task.h>
3+
#include <esp_log.h>
4+
#include <esp_err.h>
5+
#include "led_matrix.h"
6+
7+
static const char *TAG = "led_matrix";
8+
9+
static void blink_all(led_matrix *m)
10+
{
11+
ESP_ERROR_CHECK(led_matrix_set_data_raw(m, 0xFFFFFFFF));
12+
ESP_ERROR_CHECK(led_matrix_write(m, LED_MATRIX_OUTPUT_PAR));
13+
vTaskDelay(pdMS_TO_TICKS(1500));
14+
15+
ESP_ERROR_CHECK(led_matrix_set_data_raw(m, 0x00000000));
16+
ESP_ERROR_CHECK(led_matrix_write(m, LED_MATRIX_OUTPUT_PAR));
17+
vTaskDelay(pdMS_TO_TICKS(200));
18+
}
19+
20+
static void game_of_life(led_matrix *m, int rows, int cols, TickType_t frame_ms)
21+
{
22+
// Fixed pattern chosen to give a long, interesting evolution
23+
// on the 5x6 toroidal grid used by this project.
24+
uint32_t frame = 0x0BFE020C;
25+
uint32_t next = 0;
26+
27+
while (1) {
28+
next = 0;
29+
30+
for (int r = 0; r < rows; r++) {
31+
for (int c = 0; c < cols; c++) {
32+
33+
int idx = r * cols + c;
34+
int alive = (frame >> idx) & 1;
35+
36+
int n = 0;
37+
for (int dr = -1; dr <= 1; dr++)
38+
for (int dc = -1; dc <= 1; dc++) {
39+
if (dr == 0 && dc == 0) continue;
40+
int rr = (r + dr + rows) % rows;
41+
int cc = (c + dc + cols) % cols;
42+
int nidx = rr * cols + cc;
43+
n += (frame >> nidx) & 1;
44+
}
45+
46+
int new_state = alive ? (n == 2 || n == 3) : (n == 3);
47+
48+
if (new_state) {
49+
next |= (1UL << idx);
50+
}
51+
}
52+
}
53+
54+
frame = next;
55+
56+
ESP_ERROR_CHECK(led_matrix_set_data(m, frame));
57+
ESP_ERROR_CHECK(led_matrix_write(m, LED_MATRIX_OUTPUT_PAR));
58+
vTaskDelay(pdMS_TO_TICKS(frame_ms));
59+
}
60+
}
61+
62+
void app_main(void)
63+
{
64+
led_matrix m = led_matrix_init();
65+
ESP_LOGI(TAG, "Shift register pins -> SDATA: %d, SRCLK: %d, RCLK: %d",
66+
m.config.sdata, m.config.srclk, m.config.rclk);
67+
68+
blink_all(&m);
69+
game_of_life(&m, CONFIG_LED_MATRIX_ROWS, CONFIG_LED_MATRIX_COLUMNS, 150);
70+
}

0 commit comments

Comments
 (0)