Skip to content

Commit 7cd23ba

Browse files
M5 RGB LEDに対応
1 parent 9b57284 commit 7cd23ba

File tree

16 files changed

+96
-80
lines changed

16 files changed

+96
-80
lines changed

atom/ex00_hello/lib_led.ino

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ MITライセンスで配布します。権利表示の改変は禁止します
1515
// https://github.com/espressif/esp-idf/blob/master/components/esp_common/include/esp_idf_version.h
1616
#endif
1717

18+
#define NUM_LEDS 3 // LED数 1~3に対応
19+
1820
void print_esp_idf_version(){
1921
Serial.print(ESP_IDF_VERSION >> 16);
2022
Serial.print(".");
@@ -25,14 +27,14 @@ void print_esp_idf_version(){
2527

2628
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5,0,0)
2729

28-
rmt_data_t led_data[24];
30+
rmt_data_t led_data[NUM_LEDS * 24];
2931
int _PIN_LED = 0;
3032

3133
void led(int r,int g,int b){ // LEDにカラーを設定
3234
if(_PIN_LED == 0) return;
3335
uint32_t rgb = (g & 0xff) << 16 | (r & 0xff) << 8 | (b & 0xff);
34-
for (int bit = 0; bit < 24; bit++) {
35-
if ((rgb & (1 << (23 - bit))) ) {
36+
for (int bit = 0; bit < NUM_LEDS * 24; bit++) {
37+
if ((rgb & (1 << (23 - (bit % 24)))) ) {
3638
led_data[bit].level0 = 1;
3739
led_data[bit].duration0 = 8;
3840
led_data[bit].level1 = 0;
@@ -44,7 +46,7 @@ void led(int r,int g,int b){ // LEDにカラーを設定
4446
led_data[bit].duration1 = 8;
4547
}
4648
}
47-
rmtWrite(_PIN_LED, led_data, 24, RMT_WAIT_FOR_EVER);
49+
rmtWrite(_PIN_LED, led_data, NUM_LEDS * 24, RMT_WAIT_FOR_EVER);
4850
}
4951

5052
void led(int brightness){ // グレースケール制御
@@ -149,7 +151,6 @@ void loop() {
149151
#define LED_RMT_TX_CHANNEL (rmt_channel_t)0
150152
int _PIN_LED = 8;
151153

152-
#define NUM_LEDS 3
153154
#define BITS_PER_LED_CMD 24
154155
#define LED_BUFFER_ITEMS ((NUM_LEDS * BITS_PER_LED_CMD))
155156

atom/ex01_led/lib_led.ino

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ MITライセンスで配布します。権利表示の改変は禁止します
1515
// https://github.com/espressif/esp-idf/blob/master/components/esp_common/include/esp_idf_version.h
1616
#endif
1717

18+
#define NUM_LEDS 3 // LED数 1~3に対応
19+
1820
void print_esp_idf_version(){
1921
Serial.print(ESP_IDF_VERSION >> 16);
2022
Serial.print(".");
@@ -25,14 +27,14 @@ void print_esp_idf_version(){
2527

2628
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5,0,0)
2729

28-
rmt_data_t led_data[24];
30+
rmt_data_t led_data[NUM_LEDS * 24];
2931
int _PIN_LED = 0;
3032

3133
void led(int r,int g,int b){ // LEDにカラーを設定
3234
if(_PIN_LED == 0) return;
3335
uint32_t rgb = (g & 0xff) << 16 | (r & 0xff) << 8 | (b & 0xff);
34-
for (int bit = 0; bit < 24; bit++) {
35-
if ((rgb & (1 << (23 - bit))) ) {
36+
for (int bit = 0; bit < NUM_LEDS * 24; bit++) {
37+
if ((rgb & (1 << (23 - (bit % 24)))) ) {
3638
led_data[bit].level0 = 1;
3739
led_data[bit].duration0 = 8;
3840
led_data[bit].level1 = 0;
@@ -44,7 +46,7 @@ void led(int r,int g,int b){ // LEDにカラーを設定
4446
led_data[bit].duration1 = 8;
4547
}
4648
}
47-
rmtWrite(_PIN_LED, led_data, 24, RMT_WAIT_FOR_EVER);
49+
rmtWrite(_PIN_LED, led_data, NUM_LEDS * 24, RMT_WAIT_FOR_EVER);
4850
}
4951

5052
void led(int brightness){ // グレースケール制御
@@ -149,7 +151,6 @@ void loop() {
149151
#define LED_RMT_TX_CHANNEL (rmt_channel_t)0
150152
int _PIN_LED = 8;
151153

152-
#define NUM_LEDS 3
153154
#define BITS_PER_LED_CMD 24
154155
#define LED_BUFFER_ITEMS ((NUM_LEDS * BITS_PER_LED_CMD))
155156

atom/ex02_sw/lib_led.ino

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ MITライセンスで配布します。権利表示の改変は禁止します
1515
// https://github.com/espressif/esp-idf/blob/master/components/esp_common/include/esp_idf_version.h
1616
#endif
1717

18+
#define NUM_LEDS 3 // LED数 1~3に対応
19+
1820
void print_esp_idf_version(){
1921
Serial.print(ESP_IDF_VERSION >> 16);
2022
Serial.print(".");
@@ -25,14 +27,14 @@ void print_esp_idf_version(){
2527

2628
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5,0,0)
2729

28-
rmt_data_t led_data[24];
30+
rmt_data_t led_data[NUM_LEDS * 24];
2931
int _PIN_LED = 0;
3032

3133
void led(int r,int g,int b){ // LEDにカラーを設定
3234
if(_PIN_LED == 0) return;
3335
uint32_t rgb = (g & 0xff) << 16 | (r & 0xff) << 8 | (b & 0xff);
34-
for (int bit = 0; bit < 24; bit++) {
35-
if ((rgb & (1 << (23 - bit))) ) {
36+
for (int bit = 0; bit < NUM_LEDS * 24; bit++) {
37+
if ((rgb & (1 << (23 - (bit % 24)))) ) {
3638
led_data[bit].level0 = 1;
3739
led_data[bit].duration0 = 8;
3840
led_data[bit].level1 = 0;
@@ -44,7 +46,7 @@ void led(int r,int g,int b){ // LEDにカラーを設定
4446
led_data[bit].duration1 = 8;
4547
}
4648
}
47-
rmtWrite(_PIN_LED, led_data, 24, RMT_WAIT_FOR_EVER);
49+
rmtWrite(_PIN_LED, led_data, NUM_LEDS * 24, RMT_WAIT_FOR_EVER);
4850
}
4951

5052
void led(int brightness){ // グレースケール制御
@@ -149,7 +151,6 @@ void loop() {
149151
#define LED_RMT_TX_CHANNEL (rmt_channel_t)0
150152
int _PIN_LED = 8;
151153

152-
#define NUM_LEDS 3
153154
#define BITS_PER_LED_CMD 24
154155
#define LED_BUFFER_ITEMS ((NUM_LEDS * BITS_PER_LED_CMD))
155156

atom/ex02_sw_line/lib_led.ino

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ MITライセンスで配布します。権利表示の改変は禁止します
1515
// https://github.com/espressif/esp-idf/blob/master/components/esp_common/include/esp_idf_version.h
1616
#endif
1717

18+
#define NUM_LEDS 3 // LED数 1~3に対応
19+
1820
void print_esp_idf_version(){
1921
Serial.print(ESP_IDF_VERSION >> 16);
2022
Serial.print(".");
@@ -25,14 +27,14 @@ void print_esp_idf_version(){
2527

2628
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5,0,0)
2729

28-
rmt_data_t led_data[24];
30+
rmt_data_t led_data[NUM_LEDS * 24];
2931
int _PIN_LED = 0;
3032

3133
void led(int r,int g,int b){ // LEDにカラーを設定
3234
if(_PIN_LED == 0) return;
3335
uint32_t rgb = (g & 0xff) << 16 | (r & 0xff) << 8 | (b & 0xff);
34-
for (int bit = 0; bit < 24; bit++) {
35-
if ((rgb & (1 << (23 - bit))) ) {
36+
for (int bit = 0; bit < NUM_LEDS * 24; bit++) {
37+
if ((rgb & (1 << (23 - (bit % 24)))) ) {
3638
led_data[bit].level0 = 1;
3739
led_data[bit].duration0 = 8;
3840
led_data[bit].level1 = 0;
@@ -44,7 +46,7 @@ void led(int r,int g,int b){ // LEDにカラーを設定
4446
led_data[bit].duration1 = 8;
4547
}
4648
}
47-
rmtWrite(_PIN_LED, led_data, 24, RMT_WAIT_FOR_EVER);
49+
rmtWrite(_PIN_LED, led_data, NUM_LEDS * 24, RMT_WAIT_FOR_EVER);
4850
}
4951

5052
void led(int brightness){ // グレースケール制御
@@ -149,7 +151,6 @@ void loop() {
149151
#define LED_RMT_TX_CHANNEL (rmt_channel_t)0
150152
int _PIN_LED = 8;
151153

152-
#define NUM_LEDS 3
153154
#define BITS_PER_LED_CMD 24
154155
#define LED_BUFFER_ITEMS ((NUM_LEDS * BITS_PER_LED_CMD))
155156

atom/ex03_lum/lib_led.ino

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ MITライセンスで配布します。権利表示の改変は禁止します
1515
// https://github.com/espressif/esp-idf/blob/master/components/esp_common/include/esp_idf_version.h
1616
#endif
1717

18+
#define NUM_LEDS 3 // LED数 1~3に対応
19+
1820
void print_esp_idf_version(){
1921
Serial.print(ESP_IDF_VERSION >> 16);
2022
Serial.print(".");
@@ -25,14 +27,14 @@ void print_esp_idf_version(){
2527

2628
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5,0,0)
2729

28-
rmt_data_t led_data[24];
30+
rmt_data_t led_data[NUM_LEDS * 24];
2931
int _PIN_LED = 0;
3032

3133
void led(int r,int g,int b){ // LEDにカラーを設定
3234
if(_PIN_LED == 0) return;
3335
uint32_t rgb = (g & 0xff) << 16 | (r & 0xff) << 8 | (b & 0xff);
34-
for (int bit = 0; bit < 24; bit++) {
35-
if ((rgb & (1 << (23 - bit))) ) {
36+
for (int bit = 0; bit < NUM_LEDS * 24; bit++) {
37+
if ((rgb & (1 << (23 - (bit % 24)))) ) {
3638
led_data[bit].level0 = 1;
3739
led_data[bit].duration0 = 8;
3840
led_data[bit].level1 = 0;
@@ -44,7 +46,7 @@ void led(int r,int g,int b){ // LEDにカラーを設定
4446
led_data[bit].duration1 = 8;
4547
}
4648
}
47-
rmtWrite(_PIN_LED, led_data, 24, RMT_WAIT_FOR_EVER);
49+
rmtWrite(_PIN_LED, led_data, NUM_LEDS * 24, RMT_WAIT_FOR_EVER);
4850
}
4951

5052
void led(int brightness){ // グレースケール制御
@@ -149,7 +151,6 @@ void loop() {
149151
#define LED_RMT_TX_CHANNEL (rmt_channel_t)0
150152
int _PIN_LED = 8;
151153

152-
#define NUM_LEDS 3
153154
#define BITS_PER_LED_CMD 24
154155
#define LED_BUFFER_ITEMS ((NUM_LEDS * BITS_PER_LED_CMD))
155156

atom/ex04_lcd/lib_led.ino

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ MITライセンスで配布します。権利表示の改変は禁止します
1515
// https://github.com/espressif/esp-idf/blob/master/components/esp_common/include/esp_idf_version.h
1616
#endif
1717

18+
#define NUM_LEDS 3 // LED数 1~3に対応
19+
1820
void print_esp_idf_version(){
1921
Serial.print(ESP_IDF_VERSION >> 16);
2022
Serial.print(".");
@@ -25,14 +27,14 @@ void print_esp_idf_version(){
2527

2628
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5,0,0)
2729

28-
rmt_data_t led_data[24];
30+
rmt_data_t led_data[NUM_LEDS * 24];
2931
int _PIN_LED = 0;
3032

3133
void led(int r,int g,int b){ // LEDにカラーを設定
3234
if(_PIN_LED == 0) return;
3335
uint32_t rgb = (g & 0xff) << 16 | (r & 0xff) << 8 | (b & 0xff);
34-
for (int bit = 0; bit < 24; bit++) {
35-
if ((rgb & (1 << (23 - bit))) ) {
36+
for (int bit = 0; bit < NUM_LEDS * 24; bit++) {
37+
if ((rgb & (1 << (23 - (bit % 24)))) ) {
3638
led_data[bit].level0 = 1;
3739
led_data[bit].duration0 = 8;
3840
led_data[bit].level1 = 0;
@@ -44,7 +46,7 @@ void led(int r,int g,int b){ // LEDにカラーを設定
4446
led_data[bit].duration1 = 8;
4547
}
4648
}
47-
rmtWrite(_PIN_LED, led_data, 24, RMT_WAIT_FOR_EVER);
49+
rmtWrite(_PIN_LED, led_data, NUM_LEDS * 24, RMT_WAIT_FOR_EVER);
4850
}
4951

5052
void led(int brightness){ // グレースケール制御
@@ -149,7 +151,6 @@ void loop() {
149151
#define LED_RMT_TX_CHANNEL (rmt_channel_t)0
150152
int _PIN_LED = 8;
151153

152-
#define NUM_LEDS 3
153154
#define BITS_PER_LED_CMD 24
154155
#define LED_BUFFER_ITEMS ((NUM_LEDS * BITS_PER_LED_CMD))
155156

atom/ex05_hum/lib_led.ino

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ MITライセンスで配布します。権利表示の改変は禁止します
1515
// https://github.com/espressif/esp-idf/blob/master/components/esp_common/include/esp_idf_version.h
1616
#endif
1717

18+
#define NUM_LEDS 3 // LED数 1~3に対応
19+
1820
void print_esp_idf_version(){
1921
Serial.print(ESP_IDF_VERSION >> 16);
2022
Serial.print(".");
@@ -25,14 +27,14 @@ void print_esp_idf_version(){
2527

2628
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5,0,0)
2729

28-
rmt_data_t led_data[24];
30+
rmt_data_t led_data[NUM_LEDS * 24];
2931
int _PIN_LED = 0;
3032

3133
void led(int r,int g,int b){ // LEDにカラーを設定
3234
if(_PIN_LED == 0) return;
3335
uint32_t rgb = (g & 0xff) << 16 | (r & 0xff) << 8 | (b & 0xff);
34-
for (int bit = 0; bit < 24; bit++) {
35-
if ((rgb & (1 << (23 - bit))) ) {
36+
for (int bit = 0; bit < NUM_LEDS * 24; bit++) {
37+
if ((rgb & (1 << (23 - (bit % 24)))) ) {
3638
led_data[bit].level0 = 1;
3739
led_data[bit].duration0 = 8;
3840
led_data[bit].level1 = 0;
@@ -44,7 +46,7 @@ void led(int r,int g,int b){ // LEDにカラーを設定
4446
led_data[bit].duration1 = 8;
4547
}
4648
}
47-
rmtWrite(_PIN_LED, led_data, 24, RMT_WAIT_FOR_EVER);
49+
rmtWrite(_PIN_LED, led_data, NUM_LEDS * 24, RMT_WAIT_FOR_EVER);
4850
}
4951

5052
void led(int brightness){ // グレースケール制御
@@ -149,7 +151,6 @@ void loop() {
149151
#define LED_RMT_TX_CHANNEL (rmt_channel_t)0
150152
int _PIN_LED = 8;
151153

152-
#define NUM_LEDS 3
153154
#define BITS_PER_LED_CMD 24
154155
#define LED_BUFFER_ITEMS ((NUM_LEDS * BITS_PER_LED_CMD))
155156

atom/ex06_pir/lib_led.ino

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ MITライセンスで配布します。権利表示の改変は禁止します
1515
// https://github.com/espressif/esp-idf/blob/master/components/esp_common/include/esp_idf_version.h
1616
#endif
1717

18+
#define NUM_LEDS 3 // LED数 1~3に対応
19+
1820
void print_esp_idf_version(){
1921
Serial.print(ESP_IDF_VERSION >> 16);
2022
Serial.print(".");
@@ -25,14 +27,14 @@ void print_esp_idf_version(){
2527

2628
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5,0,0)
2729

28-
rmt_data_t led_data[24];
30+
rmt_data_t led_data[NUM_LEDS * 24];
2931
int _PIN_LED = 0;
3032

3133
void led(int r,int g,int b){ // LEDにカラーを設定
3234
if(_PIN_LED == 0) return;
3335
uint32_t rgb = (g & 0xff) << 16 | (r & 0xff) << 8 | (b & 0xff);
34-
for (int bit = 0; bit < 24; bit++) {
35-
if ((rgb & (1 << (23 - bit))) ) {
36+
for (int bit = 0; bit < NUM_LEDS * 24; bit++) {
37+
if ((rgb & (1 << (23 - (bit % 24)))) ) {
3638
led_data[bit].level0 = 1;
3739
led_data[bit].duration0 = 8;
3840
led_data[bit].level1 = 0;
@@ -44,7 +46,7 @@ void led(int r,int g,int b){ // LEDにカラーを設定
4446
led_data[bit].duration1 = 8;
4547
}
4648
}
47-
rmtWrite(_PIN_LED, led_data, 24, RMT_WAIT_FOR_EVER);
49+
rmtWrite(_PIN_LED, led_data, NUM_LEDS * 24, RMT_WAIT_FOR_EVER);
4850
}
4951

5052
void led(int brightness){ // グレースケール制御
@@ -149,7 +151,6 @@ void loop() {
149151
#define LED_RMT_TX_CHANNEL (rmt_channel_t)0
150152
int _PIN_LED = 8;
151153

152-
#define NUM_LEDS 3
153154
#define BITS_PER_LED_CMD 24
154155
#define LED_BUFFER_ITEMS ((NUM_LEDS * BITS_PER_LED_CMD))
155156

atom/ex06_pir_line/lib_led.ino

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ MITライセンスで配布します。権利表示の改変は禁止します
1515
// https://github.com/espressif/esp-idf/blob/master/components/esp_common/include/esp_idf_version.h
1616
#endif
1717

18+
#define NUM_LEDS 3 // LED数 1~3に対応
19+
1820
void print_esp_idf_version(){
1921
Serial.print(ESP_IDF_VERSION >> 16);
2022
Serial.print(".");
@@ -25,14 +27,14 @@ void print_esp_idf_version(){
2527

2628
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5,0,0)
2729

28-
rmt_data_t led_data[24];
30+
rmt_data_t led_data[NUM_LEDS * 24];
2931
int _PIN_LED = 0;
3032

3133
void led(int r,int g,int b){ // LEDにカラーを設定
3234
if(_PIN_LED == 0) return;
3335
uint32_t rgb = (g & 0xff) << 16 | (r & 0xff) << 8 | (b & 0xff);
34-
for (int bit = 0; bit < 24; bit++) {
35-
if ((rgb & (1 << (23 - bit))) ) {
36+
for (int bit = 0; bit < NUM_LEDS * 24; bit++) {
37+
if ((rgb & (1 << (23 - (bit % 24)))) ) {
3638
led_data[bit].level0 = 1;
3739
led_data[bit].duration0 = 8;
3840
led_data[bit].level1 = 0;
@@ -44,7 +46,7 @@ void led(int r,int g,int b){ // LEDにカラーを設定
4446
led_data[bit].duration1 = 8;
4547
}
4648
}
47-
rmtWrite(_PIN_LED, led_data, 24, RMT_WAIT_FOR_EVER);
49+
rmtWrite(_PIN_LED, led_data, NUM_LEDS * 24, RMT_WAIT_FOR_EVER);
4850
}
4951

5052
void led(int brightness){ // グレースケール制御
@@ -149,7 +151,6 @@ void loop() {
149151
#define LED_RMT_TX_CHANNEL (rmt_channel_t)0
150152
int _PIN_LED = 8;
151153

152-
#define NUM_LEDS 3
153154
#define BITS_PER_LED_CMD 24
154155
#define LED_BUFFER_ITEMS ((NUM_LEDS * BITS_PER_LED_CMD))
155156

0 commit comments

Comments
 (0)