From 7cd23ba4851a8507c5cf1700b6047f0008045f8d Mon Sep 17 00:00:00 2001 From: Wataru KUNINO Date: Tue, 24 Dec 2024 20:35:34 +0900 Subject: [PATCH] =?UTF-8?q?M5=20RGB=20LED=E3=81=AB=E5=AF=BE=E5=BF=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- atom/ex00_hello/lib_led.ino | 11 ++++++----- atom/ex01_led/lib_led.ino | 11 ++++++----- atom/ex02_sw/lib_led.ino | 11 ++++++----- atom/ex02_sw_line/lib_led.ino | 11 ++++++----- atom/ex03_lum/lib_led.ino | 11 ++++++----- atom/ex04_lcd/lib_led.ino | 11 ++++++----- atom/ex05_hum/lib_led.ino | 11 ++++++----- atom/ex06_pir/lib_led.ino | 11 ++++++----- atom/ex06_pir_line/lib_led.ino | 11 ++++++----- atom/ex07_gps/lib_led.ino | 11 ++++++----- atom/ex08_ir_out/lib_led.ino | 11 ++++++----- atom/ex09_talk/lib_led.ino | 11 ++++++----- atom_s3/ex01_led/lib_led.ino | 11 ++++++----- core/ex01_led/lib_led.ino | 11 ++++++----- core/ex01_led_sd/lib_led.ino | 11 ++++++----- core2/ex01_led/lib_led.ino | 11 ++++++----- 16 files changed, 96 insertions(+), 80 deletions(-) diff --git a/atom/ex00_hello/lib_led.ino b/atom/ex00_hello/lib_led.ino index ef18540..56fd157 100644 --- a/atom/ex00_hello/lib_led.ino +++ b/atom/ex00_hello/lib_led.ino @@ -15,6 +15,8 @@ MITライセンスで配布します。権利表示の改変は禁止します // https://github.com/espressif/esp-idf/blob/master/components/esp_common/include/esp_idf_version.h #endif +#define NUM_LEDS 3 // LED数 1~3に対応 + void print_esp_idf_version(){ Serial.print(ESP_IDF_VERSION >> 16); Serial.print("."); @@ -25,14 +27,14 @@ void print_esp_idf_version(){ #if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5,0,0) -rmt_data_t led_data[24]; +rmt_data_t led_data[NUM_LEDS * 24]; int _PIN_LED = 0; void led(int r,int g,int b){ // LEDにカラーを設定 if(_PIN_LED == 0) return; uint32_t rgb = (g & 0xff) << 16 | (r & 0xff) << 8 | (b & 0xff); - for (int bit = 0; bit < 24; bit++) { - if ((rgb & (1 << (23 - bit))) ) { + for (int bit = 0; bit < NUM_LEDS * 24; bit++) { + if ((rgb & (1 << (23 - (bit % 24)))) ) { led_data[bit].level0 = 1; led_data[bit].duration0 = 8; led_data[bit].level1 = 0; @@ -44,7 +46,7 @@ void led(int r,int g,int b){ // LEDにカラーを設定 led_data[bit].duration1 = 8; } } - rmtWrite(_PIN_LED, led_data, 24, RMT_WAIT_FOR_EVER); + rmtWrite(_PIN_LED, led_data, NUM_LEDS * 24, RMT_WAIT_FOR_EVER); } void led(int brightness){ // グレースケール制御 @@ -149,7 +151,6 @@ void loop() { #define LED_RMT_TX_CHANNEL (rmt_channel_t)0 int _PIN_LED = 8; -#define NUM_LEDS 3 #define BITS_PER_LED_CMD 24 #define LED_BUFFER_ITEMS ((NUM_LEDS * BITS_PER_LED_CMD)) diff --git a/atom/ex01_led/lib_led.ino b/atom/ex01_led/lib_led.ino index ef18540..56fd157 100644 --- a/atom/ex01_led/lib_led.ino +++ b/atom/ex01_led/lib_led.ino @@ -15,6 +15,8 @@ MITライセンスで配布します。権利表示の改変は禁止します // https://github.com/espressif/esp-idf/blob/master/components/esp_common/include/esp_idf_version.h #endif +#define NUM_LEDS 3 // LED数 1~3に対応 + void print_esp_idf_version(){ Serial.print(ESP_IDF_VERSION >> 16); Serial.print("."); @@ -25,14 +27,14 @@ void print_esp_idf_version(){ #if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5,0,0) -rmt_data_t led_data[24]; +rmt_data_t led_data[NUM_LEDS * 24]; int _PIN_LED = 0; void led(int r,int g,int b){ // LEDにカラーを設定 if(_PIN_LED == 0) return; uint32_t rgb = (g & 0xff) << 16 | (r & 0xff) << 8 | (b & 0xff); - for (int bit = 0; bit < 24; bit++) { - if ((rgb & (1 << (23 - bit))) ) { + for (int bit = 0; bit < NUM_LEDS * 24; bit++) { + if ((rgb & (1 << (23 - (bit % 24)))) ) { led_data[bit].level0 = 1; led_data[bit].duration0 = 8; led_data[bit].level1 = 0; @@ -44,7 +46,7 @@ void led(int r,int g,int b){ // LEDにカラーを設定 led_data[bit].duration1 = 8; } } - rmtWrite(_PIN_LED, led_data, 24, RMT_WAIT_FOR_EVER); + rmtWrite(_PIN_LED, led_data, NUM_LEDS * 24, RMT_WAIT_FOR_EVER); } void led(int brightness){ // グレースケール制御 @@ -149,7 +151,6 @@ void loop() { #define LED_RMT_TX_CHANNEL (rmt_channel_t)0 int _PIN_LED = 8; -#define NUM_LEDS 3 #define BITS_PER_LED_CMD 24 #define LED_BUFFER_ITEMS ((NUM_LEDS * BITS_PER_LED_CMD)) diff --git a/atom/ex02_sw/lib_led.ino b/atom/ex02_sw/lib_led.ino index ef18540..56fd157 100644 --- a/atom/ex02_sw/lib_led.ino +++ b/atom/ex02_sw/lib_led.ino @@ -15,6 +15,8 @@ MITライセンスで配布します。権利表示の改変は禁止します // https://github.com/espressif/esp-idf/blob/master/components/esp_common/include/esp_idf_version.h #endif +#define NUM_LEDS 3 // LED数 1~3に対応 + void print_esp_idf_version(){ Serial.print(ESP_IDF_VERSION >> 16); Serial.print("."); @@ -25,14 +27,14 @@ void print_esp_idf_version(){ #if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5,0,0) -rmt_data_t led_data[24]; +rmt_data_t led_data[NUM_LEDS * 24]; int _PIN_LED = 0; void led(int r,int g,int b){ // LEDにカラーを設定 if(_PIN_LED == 0) return; uint32_t rgb = (g & 0xff) << 16 | (r & 0xff) << 8 | (b & 0xff); - for (int bit = 0; bit < 24; bit++) { - if ((rgb & (1 << (23 - bit))) ) { + for (int bit = 0; bit < NUM_LEDS * 24; bit++) { + if ((rgb & (1 << (23 - (bit % 24)))) ) { led_data[bit].level0 = 1; led_data[bit].duration0 = 8; led_data[bit].level1 = 0; @@ -44,7 +46,7 @@ void led(int r,int g,int b){ // LEDにカラーを設定 led_data[bit].duration1 = 8; } } - rmtWrite(_PIN_LED, led_data, 24, RMT_WAIT_FOR_EVER); + rmtWrite(_PIN_LED, led_data, NUM_LEDS * 24, RMT_WAIT_FOR_EVER); } void led(int brightness){ // グレースケール制御 @@ -149,7 +151,6 @@ void loop() { #define LED_RMT_TX_CHANNEL (rmt_channel_t)0 int _PIN_LED = 8; -#define NUM_LEDS 3 #define BITS_PER_LED_CMD 24 #define LED_BUFFER_ITEMS ((NUM_LEDS * BITS_PER_LED_CMD)) diff --git a/atom/ex02_sw_line/lib_led.ino b/atom/ex02_sw_line/lib_led.ino index ef18540..56fd157 100644 --- a/atom/ex02_sw_line/lib_led.ino +++ b/atom/ex02_sw_line/lib_led.ino @@ -15,6 +15,8 @@ MITライセンスで配布します。権利表示の改変は禁止します // https://github.com/espressif/esp-idf/blob/master/components/esp_common/include/esp_idf_version.h #endif +#define NUM_LEDS 3 // LED数 1~3に対応 + void print_esp_idf_version(){ Serial.print(ESP_IDF_VERSION >> 16); Serial.print("."); @@ -25,14 +27,14 @@ void print_esp_idf_version(){ #if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5,0,0) -rmt_data_t led_data[24]; +rmt_data_t led_data[NUM_LEDS * 24]; int _PIN_LED = 0; void led(int r,int g,int b){ // LEDにカラーを設定 if(_PIN_LED == 0) return; uint32_t rgb = (g & 0xff) << 16 | (r & 0xff) << 8 | (b & 0xff); - for (int bit = 0; bit < 24; bit++) { - if ((rgb & (1 << (23 - bit))) ) { + for (int bit = 0; bit < NUM_LEDS * 24; bit++) { + if ((rgb & (1 << (23 - (bit % 24)))) ) { led_data[bit].level0 = 1; led_data[bit].duration0 = 8; led_data[bit].level1 = 0; @@ -44,7 +46,7 @@ void led(int r,int g,int b){ // LEDにカラーを設定 led_data[bit].duration1 = 8; } } - rmtWrite(_PIN_LED, led_data, 24, RMT_WAIT_FOR_EVER); + rmtWrite(_PIN_LED, led_data, NUM_LEDS * 24, RMT_WAIT_FOR_EVER); } void led(int brightness){ // グレースケール制御 @@ -149,7 +151,6 @@ void loop() { #define LED_RMT_TX_CHANNEL (rmt_channel_t)0 int _PIN_LED = 8; -#define NUM_LEDS 3 #define BITS_PER_LED_CMD 24 #define LED_BUFFER_ITEMS ((NUM_LEDS * BITS_PER_LED_CMD)) diff --git a/atom/ex03_lum/lib_led.ino b/atom/ex03_lum/lib_led.ino index ef18540..56fd157 100644 --- a/atom/ex03_lum/lib_led.ino +++ b/atom/ex03_lum/lib_led.ino @@ -15,6 +15,8 @@ MITライセンスで配布します。権利表示の改変は禁止します // https://github.com/espressif/esp-idf/blob/master/components/esp_common/include/esp_idf_version.h #endif +#define NUM_LEDS 3 // LED数 1~3に対応 + void print_esp_idf_version(){ Serial.print(ESP_IDF_VERSION >> 16); Serial.print("."); @@ -25,14 +27,14 @@ void print_esp_idf_version(){ #if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5,0,0) -rmt_data_t led_data[24]; +rmt_data_t led_data[NUM_LEDS * 24]; int _PIN_LED = 0; void led(int r,int g,int b){ // LEDにカラーを設定 if(_PIN_LED == 0) return; uint32_t rgb = (g & 0xff) << 16 | (r & 0xff) << 8 | (b & 0xff); - for (int bit = 0; bit < 24; bit++) { - if ((rgb & (1 << (23 - bit))) ) { + for (int bit = 0; bit < NUM_LEDS * 24; bit++) { + if ((rgb & (1 << (23 - (bit % 24)))) ) { led_data[bit].level0 = 1; led_data[bit].duration0 = 8; led_data[bit].level1 = 0; @@ -44,7 +46,7 @@ void led(int r,int g,int b){ // LEDにカラーを設定 led_data[bit].duration1 = 8; } } - rmtWrite(_PIN_LED, led_data, 24, RMT_WAIT_FOR_EVER); + rmtWrite(_PIN_LED, led_data, NUM_LEDS * 24, RMT_WAIT_FOR_EVER); } void led(int brightness){ // グレースケール制御 @@ -149,7 +151,6 @@ void loop() { #define LED_RMT_TX_CHANNEL (rmt_channel_t)0 int _PIN_LED = 8; -#define NUM_LEDS 3 #define BITS_PER_LED_CMD 24 #define LED_BUFFER_ITEMS ((NUM_LEDS * BITS_PER_LED_CMD)) diff --git a/atom/ex04_lcd/lib_led.ino b/atom/ex04_lcd/lib_led.ino index ef18540..56fd157 100644 --- a/atom/ex04_lcd/lib_led.ino +++ b/atom/ex04_lcd/lib_led.ino @@ -15,6 +15,8 @@ MITライセンスで配布します。権利表示の改変は禁止します // https://github.com/espressif/esp-idf/blob/master/components/esp_common/include/esp_idf_version.h #endif +#define NUM_LEDS 3 // LED数 1~3に対応 + void print_esp_idf_version(){ Serial.print(ESP_IDF_VERSION >> 16); Serial.print("."); @@ -25,14 +27,14 @@ void print_esp_idf_version(){ #if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5,0,0) -rmt_data_t led_data[24]; +rmt_data_t led_data[NUM_LEDS * 24]; int _PIN_LED = 0; void led(int r,int g,int b){ // LEDにカラーを設定 if(_PIN_LED == 0) return; uint32_t rgb = (g & 0xff) << 16 | (r & 0xff) << 8 | (b & 0xff); - for (int bit = 0; bit < 24; bit++) { - if ((rgb & (1 << (23 - bit))) ) { + for (int bit = 0; bit < NUM_LEDS * 24; bit++) { + if ((rgb & (1 << (23 - (bit % 24)))) ) { led_data[bit].level0 = 1; led_data[bit].duration0 = 8; led_data[bit].level1 = 0; @@ -44,7 +46,7 @@ void led(int r,int g,int b){ // LEDにカラーを設定 led_data[bit].duration1 = 8; } } - rmtWrite(_PIN_LED, led_data, 24, RMT_WAIT_FOR_EVER); + rmtWrite(_PIN_LED, led_data, NUM_LEDS * 24, RMT_WAIT_FOR_EVER); } void led(int brightness){ // グレースケール制御 @@ -149,7 +151,6 @@ void loop() { #define LED_RMT_TX_CHANNEL (rmt_channel_t)0 int _PIN_LED = 8; -#define NUM_LEDS 3 #define BITS_PER_LED_CMD 24 #define LED_BUFFER_ITEMS ((NUM_LEDS * BITS_PER_LED_CMD)) diff --git a/atom/ex05_hum/lib_led.ino b/atom/ex05_hum/lib_led.ino index ef18540..56fd157 100644 --- a/atom/ex05_hum/lib_led.ino +++ b/atom/ex05_hum/lib_led.ino @@ -15,6 +15,8 @@ MITライセンスで配布します。権利表示の改変は禁止します // https://github.com/espressif/esp-idf/blob/master/components/esp_common/include/esp_idf_version.h #endif +#define NUM_LEDS 3 // LED数 1~3に対応 + void print_esp_idf_version(){ Serial.print(ESP_IDF_VERSION >> 16); Serial.print("."); @@ -25,14 +27,14 @@ void print_esp_idf_version(){ #if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5,0,0) -rmt_data_t led_data[24]; +rmt_data_t led_data[NUM_LEDS * 24]; int _PIN_LED = 0; void led(int r,int g,int b){ // LEDにカラーを設定 if(_PIN_LED == 0) return; uint32_t rgb = (g & 0xff) << 16 | (r & 0xff) << 8 | (b & 0xff); - for (int bit = 0; bit < 24; bit++) { - if ((rgb & (1 << (23 - bit))) ) { + for (int bit = 0; bit < NUM_LEDS * 24; bit++) { + if ((rgb & (1 << (23 - (bit % 24)))) ) { led_data[bit].level0 = 1; led_data[bit].duration0 = 8; led_data[bit].level1 = 0; @@ -44,7 +46,7 @@ void led(int r,int g,int b){ // LEDにカラーを設定 led_data[bit].duration1 = 8; } } - rmtWrite(_PIN_LED, led_data, 24, RMT_WAIT_FOR_EVER); + rmtWrite(_PIN_LED, led_data, NUM_LEDS * 24, RMT_WAIT_FOR_EVER); } void led(int brightness){ // グレースケール制御 @@ -149,7 +151,6 @@ void loop() { #define LED_RMT_TX_CHANNEL (rmt_channel_t)0 int _PIN_LED = 8; -#define NUM_LEDS 3 #define BITS_PER_LED_CMD 24 #define LED_BUFFER_ITEMS ((NUM_LEDS * BITS_PER_LED_CMD)) diff --git a/atom/ex06_pir/lib_led.ino b/atom/ex06_pir/lib_led.ino index ef18540..56fd157 100644 --- a/atom/ex06_pir/lib_led.ino +++ b/atom/ex06_pir/lib_led.ino @@ -15,6 +15,8 @@ MITライセンスで配布します。権利表示の改変は禁止します // https://github.com/espressif/esp-idf/blob/master/components/esp_common/include/esp_idf_version.h #endif +#define NUM_LEDS 3 // LED数 1~3に対応 + void print_esp_idf_version(){ Serial.print(ESP_IDF_VERSION >> 16); Serial.print("."); @@ -25,14 +27,14 @@ void print_esp_idf_version(){ #if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5,0,0) -rmt_data_t led_data[24]; +rmt_data_t led_data[NUM_LEDS * 24]; int _PIN_LED = 0; void led(int r,int g,int b){ // LEDにカラーを設定 if(_PIN_LED == 0) return; uint32_t rgb = (g & 0xff) << 16 | (r & 0xff) << 8 | (b & 0xff); - for (int bit = 0; bit < 24; bit++) { - if ((rgb & (1 << (23 - bit))) ) { + for (int bit = 0; bit < NUM_LEDS * 24; bit++) { + if ((rgb & (1 << (23 - (bit % 24)))) ) { led_data[bit].level0 = 1; led_data[bit].duration0 = 8; led_data[bit].level1 = 0; @@ -44,7 +46,7 @@ void led(int r,int g,int b){ // LEDにカラーを設定 led_data[bit].duration1 = 8; } } - rmtWrite(_PIN_LED, led_data, 24, RMT_WAIT_FOR_EVER); + rmtWrite(_PIN_LED, led_data, NUM_LEDS * 24, RMT_WAIT_FOR_EVER); } void led(int brightness){ // グレースケール制御 @@ -149,7 +151,6 @@ void loop() { #define LED_RMT_TX_CHANNEL (rmt_channel_t)0 int _PIN_LED = 8; -#define NUM_LEDS 3 #define BITS_PER_LED_CMD 24 #define LED_BUFFER_ITEMS ((NUM_LEDS * BITS_PER_LED_CMD)) diff --git a/atom/ex06_pir_line/lib_led.ino b/atom/ex06_pir_line/lib_led.ino index ef18540..56fd157 100644 --- a/atom/ex06_pir_line/lib_led.ino +++ b/atom/ex06_pir_line/lib_led.ino @@ -15,6 +15,8 @@ MITライセンスで配布します。権利表示の改変は禁止します // https://github.com/espressif/esp-idf/blob/master/components/esp_common/include/esp_idf_version.h #endif +#define NUM_LEDS 3 // LED数 1~3に対応 + void print_esp_idf_version(){ Serial.print(ESP_IDF_VERSION >> 16); Serial.print("."); @@ -25,14 +27,14 @@ void print_esp_idf_version(){ #if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5,0,0) -rmt_data_t led_data[24]; +rmt_data_t led_data[NUM_LEDS * 24]; int _PIN_LED = 0; void led(int r,int g,int b){ // LEDにカラーを設定 if(_PIN_LED == 0) return; uint32_t rgb = (g & 0xff) << 16 | (r & 0xff) << 8 | (b & 0xff); - for (int bit = 0; bit < 24; bit++) { - if ((rgb & (1 << (23 - bit))) ) { + for (int bit = 0; bit < NUM_LEDS * 24; bit++) { + if ((rgb & (1 << (23 - (bit % 24)))) ) { led_data[bit].level0 = 1; led_data[bit].duration0 = 8; led_data[bit].level1 = 0; @@ -44,7 +46,7 @@ void led(int r,int g,int b){ // LEDにカラーを設定 led_data[bit].duration1 = 8; } } - rmtWrite(_PIN_LED, led_data, 24, RMT_WAIT_FOR_EVER); + rmtWrite(_PIN_LED, led_data, NUM_LEDS * 24, RMT_WAIT_FOR_EVER); } void led(int brightness){ // グレースケール制御 @@ -149,7 +151,6 @@ void loop() { #define LED_RMT_TX_CHANNEL (rmt_channel_t)0 int _PIN_LED = 8; -#define NUM_LEDS 3 #define BITS_PER_LED_CMD 24 #define LED_BUFFER_ITEMS ((NUM_LEDS * BITS_PER_LED_CMD)) diff --git a/atom/ex07_gps/lib_led.ino b/atom/ex07_gps/lib_led.ino index ef18540..56fd157 100644 --- a/atom/ex07_gps/lib_led.ino +++ b/atom/ex07_gps/lib_led.ino @@ -15,6 +15,8 @@ MITライセンスで配布します。権利表示の改変は禁止します // https://github.com/espressif/esp-idf/blob/master/components/esp_common/include/esp_idf_version.h #endif +#define NUM_LEDS 3 // LED数 1~3に対応 + void print_esp_idf_version(){ Serial.print(ESP_IDF_VERSION >> 16); Serial.print("."); @@ -25,14 +27,14 @@ void print_esp_idf_version(){ #if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5,0,0) -rmt_data_t led_data[24]; +rmt_data_t led_data[NUM_LEDS * 24]; int _PIN_LED = 0; void led(int r,int g,int b){ // LEDにカラーを設定 if(_PIN_LED == 0) return; uint32_t rgb = (g & 0xff) << 16 | (r & 0xff) << 8 | (b & 0xff); - for (int bit = 0; bit < 24; bit++) { - if ((rgb & (1 << (23 - bit))) ) { + for (int bit = 0; bit < NUM_LEDS * 24; bit++) { + if ((rgb & (1 << (23 - (bit % 24)))) ) { led_data[bit].level0 = 1; led_data[bit].duration0 = 8; led_data[bit].level1 = 0; @@ -44,7 +46,7 @@ void led(int r,int g,int b){ // LEDにカラーを設定 led_data[bit].duration1 = 8; } } - rmtWrite(_PIN_LED, led_data, 24, RMT_WAIT_FOR_EVER); + rmtWrite(_PIN_LED, led_data, NUM_LEDS * 24, RMT_WAIT_FOR_EVER); } void led(int brightness){ // グレースケール制御 @@ -149,7 +151,6 @@ void loop() { #define LED_RMT_TX_CHANNEL (rmt_channel_t)0 int _PIN_LED = 8; -#define NUM_LEDS 3 #define BITS_PER_LED_CMD 24 #define LED_BUFFER_ITEMS ((NUM_LEDS * BITS_PER_LED_CMD)) diff --git a/atom/ex08_ir_out/lib_led.ino b/atom/ex08_ir_out/lib_led.ino index ef18540..56fd157 100644 --- a/atom/ex08_ir_out/lib_led.ino +++ b/atom/ex08_ir_out/lib_led.ino @@ -15,6 +15,8 @@ MITライセンスで配布します。権利表示の改変は禁止します // https://github.com/espressif/esp-idf/blob/master/components/esp_common/include/esp_idf_version.h #endif +#define NUM_LEDS 3 // LED数 1~3に対応 + void print_esp_idf_version(){ Serial.print(ESP_IDF_VERSION >> 16); Serial.print("."); @@ -25,14 +27,14 @@ void print_esp_idf_version(){ #if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5,0,0) -rmt_data_t led_data[24]; +rmt_data_t led_data[NUM_LEDS * 24]; int _PIN_LED = 0; void led(int r,int g,int b){ // LEDにカラーを設定 if(_PIN_LED == 0) return; uint32_t rgb = (g & 0xff) << 16 | (r & 0xff) << 8 | (b & 0xff); - for (int bit = 0; bit < 24; bit++) { - if ((rgb & (1 << (23 - bit))) ) { + for (int bit = 0; bit < NUM_LEDS * 24; bit++) { + if ((rgb & (1 << (23 - (bit % 24)))) ) { led_data[bit].level0 = 1; led_data[bit].duration0 = 8; led_data[bit].level1 = 0; @@ -44,7 +46,7 @@ void led(int r,int g,int b){ // LEDにカラーを設定 led_data[bit].duration1 = 8; } } - rmtWrite(_PIN_LED, led_data, 24, RMT_WAIT_FOR_EVER); + rmtWrite(_PIN_LED, led_data, NUM_LEDS * 24, RMT_WAIT_FOR_EVER); } void led(int brightness){ // グレースケール制御 @@ -149,7 +151,6 @@ void loop() { #define LED_RMT_TX_CHANNEL (rmt_channel_t)0 int _PIN_LED = 8; -#define NUM_LEDS 3 #define BITS_PER_LED_CMD 24 #define LED_BUFFER_ITEMS ((NUM_LEDS * BITS_PER_LED_CMD)) diff --git a/atom/ex09_talk/lib_led.ino b/atom/ex09_talk/lib_led.ino index ef18540..56fd157 100644 --- a/atom/ex09_talk/lib_led.ino +++ b/atom/ex09_talk/lib_led.ino @@ -15,6 +15,8 @@ MITライセンスで配布します。権利表示の改変は禁止します // https://github.com/espressif/esp-idf/blob/master/components/esp_common/include/esp_idf_version.h #endif +#define NUM_LEDS 3 // LED数 1~3に対応 + void print_esp_idf_version(){ Serial.print(ESP_IDF_VERSION >> 16); Serial.print("."); @@ -25,14 +27,14 @@ void print_esp_idf_version(){ #if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5,0,0) -rmt_data_t led_data[24]; +rmt_data_t led_data[NUM_LEDS * 24]; int _PIN_LED = 0; void led(int r,int g,int b){ // LEDにカラーを設定 if(_PIN_LED == 0) return; uint32_t rgb = (g & 0xff) << 16 | (r & 0xff) << 8 | (b & 0xff); - for (int bit = 0; bit < 24; bit++) { - if ((rgb & (1 << (23 - bit))) ) { + for (int bit = 0; bit < NUM_LEDS * 24; bit++) { + if ((rgb & (1 << (23 - (bit % 24)))) ) { led_data[bit].level0 = 1; led_data[bit].duration0 = 8; led_data[bit].level1 = 0; @@ -44,7 +46,7 @@ void led(int r,int g,int b){ // LEDにカラーを設定 led_data[bit].duration1 = 8; } } - rmtWrite(_PIN_LED, led_data, 24, RMT_WAIT_FOR_EVER); + rmtWrite(_PIN_LED, led_data, NUM_LEDS * 24, RMT_WAIT_FOR_EVER); } void led(int brightness){ // グレースケール制御 @@ -149,7 +151,6 @@ void loop() { #define LED_RMT_TX_CHANNEL (rmt_channel_t)0 int _PIN_LED = 8; -#define NUM_LEDS 3 #define BITS_PER_LED_CMD 24 #define LED_BUFFER_ITEMS ((NUM_LEDS * BITS_PER_LED_CMD)) diff --git a/atom_s3/ex01_led/lib_led.ino b/atom_s3/ex01_led/lib_led.ino index ef18540..56fd157 100644 --- a/atom_s3/ex01_led/lib_led.ino +++ b/atom_s3/ex01_led/lib_led.ino @@ -15,6 +15,8 @@ MITライセンスで配布します。権利表示の改変は禁止します // https://github.com/espressif/esp-idf/blob/master/components/esp_common/include/esp_idf_version.h #endif +#define NUM_LEDS 3 // LED数 1~3に対応 + void print_esp_idf_version(){ Serial.print(ESP_IDF_VERSION >> 16); Serial.print("."); @@ -25,14 +27,14 @@ void print_esp_idf_version(){ #if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5,0,0) -rmt_data_t led_data[24]; +rmt_data_t led_data[NUM_LEDS * 24]; int _PIN_LED = 0; void led(int r,int g,int b){ // LEDにカラーを設定 if(_PIN_LED == 0) return; uint32_t rgb = (g & 0xff) << 16 | (r & 0xff) << 8 | (b & 0xff); - for (int bit = 0; bit < 24; bit++) { - if ((rgb & (1 << (23 - bit))) ) { + for (int bit = 0; bit < NUM_LEDS * 24; bit++) { + if ((rgb & (1 << (23 - (bit % 24)))) ) { led_data[bit].level0 = 1; led_data[bit].duration0 = 8; led_data[bit].level1 = 0; @@ -44,7 +46,7 @@ void led(int r,int g,int b){ // LEDにカラーを設定 led_data[bit].duration1 = 8; } } - rmtWrite(_PIN_LED, led_data, 24, RMT_WAIT_FOR_EVER); + rmtWrite(_PIN_LED, led_data, NUM_LEDS * 24, RMT_WAIT_FOR_EVER); } void led(int brightness){ // グレースケール制御 @@ -149,7 +151,6 @@ void loop() { #define LED_RMT_TX_CHANNEL (rmt_channel_t)0 int _PIN_LED = 8; -#define NUM_LEDS 3 #define BITS_PER_LED_CMD 24 #define LED_BUFFER_ITEMS ((NUM_LEDS * BITS_PER_LED_CMD)) diff --git a/core/ex01_led/lib_led.ino b/core/ex01_led/lib_led.ino index ef18540..56fd157 100644 --- a/core/ex01_led/lib_led.ino +++ b/core/ex01_led/lib_led.ino @@ -15,6 +15,8 @@ MITライセンスで配布します。権利表示の改変は禁止します // https://github.com/espressif/esp-idf/blob/master/components/esp_common/include/esp_idf_version.h #endif +#define NUM_LEDS 3 // LED数 1~3に対応 + void print_esp_idf_version(){ Serial.print(ESP_IDF_VERSION >> 16); Serial.print("."); @@ -25,14 +27,14 @@ void print_esp_idf_version(){ #if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5,0,0) -rmt_data_t led_data[24]; +rmt_data_t led_data[NUM_LEDS * 24]; int _PIN_LED = 0; void led(int r,int g,int b){ // LEDにカラーを設定 if(_PIN_LED == 0) return; uint32_t rgb = (g & 0xff) << 16 | (r & 0xff) << 8 | (b & 0xff); - for (int bit = 0; bit < 24; bit++) { - if ((rgb & (1 << (23 - bit))) ) { + for (int bit = 0; bit < NUM_LEDS * 24; bit++) { + if ((rgb & (1 << (23 - (bit % 24)))) ) { led_data[bit].level0 = 1; led_data[bit].duration0 = 8; led_data[bit].level1 = 0; @@ -44,7 +46,7 @@ void led(int r,int g,int b){ // LEDにカラーを設定 led_data[bit].duration1 = 8; } } - rmtWrite(_PIN_LED, led_data, 24, RMT_WAIT_FOR_EVER); + rmtWrite(_PIN_LED, led_data, NUM_LEDS * 24, RMT_WAIT_FOR_EVER); } void led(int brightness){ // グレースケール制御 @@ -149,7 +151,6 @@ void loop() { #define LED_RMT_TX_CHANNEL (rmt_channel_t)0 int _PIN_LED = 8; -#define NUM_LEDS 3 #define BITS_PER_LED_CMD 24 #define LED_BUFFER_ITEMS ((NUM_LEDS * BITS_PER_LED_CMD)) diff --git a/core/ex01_led_sd/lib_led.ino b/core/ex01_led_sd/lib_led.ino index ef18540..56fd157 100644 --- a/core/ex01_led_sd/lib_led.ino +++ b/core/ex01_led_sd/lib_led.ino @@ -15,6 +15,8 @@ MITライセンスで配布します。権利表示の改変は禁止します // https://github.com/espressif/esp-idf/blob/master/components/esp_common/include/esp_idf_version.h #endif +#define NUM_LEDS 3 // LED数 1~3に対応 + void print_esp_idf_version(){ Serial.print(ESP_IDF_VERSION >> 16); Serial.print("."); @@ -25,14 +27,14 @@ void print_esp_idf_version(){ #if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5,0,0) -rmt_data_t led_data[24]; +rmt_data_t led_data[NUM_LEDS * 24]; int _PIN_LED = 0; void led(int r,int g,int b){ // LEDにカラーを設定 if(_PIN_LED == 0) return; uint32_t rgb = (g & 0xff) << 16 | (r & 0xff) << 8 | (b & 0xff); - for (int bit = 0; bit < 24; bit++) { - if ((rgb & (1 << (23 - bit))) ) { + for (int bit = 0; bit < NUM_LEDS * 24; bit++) { + if ((rgb & (1 << (23 - (bit % 24)))) ) { led_data[bit].level0 = 1; led_data[bit].duration0 = 8; led_data[bit].level1 = 0; @@ -44,7 +46,7 @@ void led(int r,int g,int b){ // LEDにカラーを設定 led_data[bit].duration1 = 8; } } - rmtWrite(_PIN_LED, led_data, 24, RMT_WAIT_FOR_EVER); + rmtWrite(_PIN_LED, led_data, NUM_LEDS * 24, RMT_WAIT_FOR_EVER); } void led(int brightness){ // グレースケール制御 @@ -149,7 +151,6 @@ void loop() { #define LED_RMT_TX_CHANNEL (rmt_channel_t)0 int _PIN_LED = 8; -#define NUM_LEDS 3 #define BITS_PER_LED_CMD 24 #define LED_BUFFER_ITEMS ((NUM_LEDS * BITS_PER_LED_CMD)) diff --git a/core2/ex01_led/lib_led.ino b/core2/ex01_led/lib_led.ino index ef18540..56fd157 100644 --- a/core2/ex01_led/lib_led.ino +++ b/core2/ex01_led/lib_led.ino @@ -15,6 +15,8 @@ MITライセンスで配布します。権利表示の改変は禁止します // https://github.com/espressif/esp-idf/blob/master/components/esp_common/include/esp_idf_version.h #endif +#define NUM_LEDS 3 // LED数 1~3に対応 + void print_esp_idf_version(){ Serial.print(ESP_IDF_VERSION >> 16); Serial.print("."); @@ -25,14 +27,14 @@ void print_esp_idf_version(){ #if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5,0,0) -rmt_data_t led_data[24]; +rmt_data_t led_data[NUM_LEDS * 24]; int _PIN_LED = 0; void led(int r,int g,int b){ // LEDにカラーを設定 if(_PIN_LED == 0) return; uint32_t rgb = (g & 0xff) << 16 | (r & 0xff) << 8 | (b & 0xff); - for (int bit = 0; bit < 24; bit++) { - if ((rgb & (1 << (23 - bit))) ) { + for (int bit = 0; bit < NUM_LEDS * 24; bit++) { + if ((rgb & (1 << (23 - (bit % 24)))) ) { led_data[bit].level0 = 1; led_data[bit].duration0 = 8; led_data[bit].level1 = 0; @@ -44,7 +46,7 @@ void led(int r,int g,int b){ // LEDにカラーを設定 led_data[bit].duration1 = 8; } } - rmtWrite(_PIN_LED, led_data, 24, RMT_WAIT_FOR_EVER); + rmtWrite(_PIN_LED, led_data, NUM_LEDS * 24, RMT_WAIT_FOR_EVER); } void led(int brightness){ // グレースケール制御 @@ -149,7 +151,6 @@ void loop() { #define LED_RMT_TX_CHANNEL (rmt_channel_t)0 int _PIN_LED = 8; -#define NUM_LEDS 3 #define BITS_PER_LED_CMD 24 #define LED_BUFFER_ITEMS ((NUM_LEDS * BITS_PER_LED_CMD))