From 8a2c070e63543c6057943d41d21cd2fcc3616ff3 Mon Sep 17 00:00:00 2001 From: Jakob Klepp Date: Fri, 12 May 2023 20:47:47 +0200 Subject: [PATCH 1/5] Var name --- ownpage-booth/gen_wave_form.js | 4 ++-- ownpage-booth/ownpage-booth.ino | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/ownpage-booth/gen_wave_form.js b/ownpage-booth/gen_wave_form.js index c2c1361..12071bc 100644 --- a/ownpage-booth/gen_wave_form.js +++ b/ownpage-booth/gen_wave_form.js @@ -1,4 +1,4 @@ -/* 180 step waveform approximation for a sine wave with amplitude 255 +/* Crude approximation of a sine wave node gen_wave_form.js @@ -8,7 +8,7 @@ Or paste in browser developer console. const steps = 180; let output = ` -const char[${steps}] = {`; +const char SINE_WAVEFORM[${steps}] = {`; for (let i = 0; i < steps; i++) { if (i % 5 === 0) { diff --git a/ownpage-booth/ownpage-booth.ino b/ownpage-booth/ownpage-booth.ino index 9b689ba..1dd46f3 100644 --- a/ownpage-booth/ownpage-booth.ino +++ b/ownpage-booth/ownpage-booth.ino @@ -153,8 +153,7 @@ const struct led_position POSITION_MAP[144] = { /* 143 */ { 285.816650390625, 47.65000915527344 }, }; - -const char[180] = { +const char SINE_WAVEFORM[180] = { /* 0 */ 0, 4, 8, 13, 17, /* 5 */ 22, 26, 31, 35, 39, /* 10 */ 44, 48, 53, 57, 61, From 983ea347d1387e4d22f54bfa760239c4ce01d9fb Mon Sep 17 00:00:00 2001 From: Jakob Klepp Date: Fri, 12 May 2023 20:55:23 +0200 Subject: [PATCH 2/5] Generate full periode --- ownpage-booth/gen_wave_form.js | 2 +- ownpage-booth/ownpage-booth.ino | 72 ++++++++++++++++----------------- 2 files changed, 37 insertions(+), 37 deletions(-) diff --git a/ownpage-booth/gen_wave_form.js b/ownpage-booth/gen_wave_form.js index 12071bc..4c9d01d 100644 --- a/ownpage-booth/gen_wave_form.js +++ b/ownpage-booth/gen_wave_form.js @@ -15,7 +15,7 @@ for (let i = 0; i < steps; i++) { output += ` /* ${i} */` } - output += ` ${Math.floor(255 * Math.sin(Math.PI / steps * i))},`; + output += ` ${Math.floor(255 * (1 + Math.sin(2 * Math.PI / steps * i)) / 2)},`; } output += ` diff --git a/ownpage-booth/ownpage-booth.ino b/ownpage-booth/ownpage-booth.ino index 1dd46f3..d0043e7 100644 --- a/ownpage-booth/ownpage-booth.ino +++ b/ownpage-booth/ownpage-booth.ino @@ -154,42 +154,42 @@ const struct led_position POSITION_MAP[144] = { }; const char SINE_WAVEFORM[180] = { - /* 0 */ 0, 4, 8, 13, 17, - /* 5 */ 22, 26, 31, 35, 39, - /* 10 */ 44, 48, 53, 57, 61, - /* 15 */ 65, 70, 74, 78, 83, - /* 20 */ 87, 91, 95, 99, 103, - /* 25 */ 107, 111, 115, 119, 123, - /* 30 */ 127, 131, 135, 138, 142, - /* 35 */ 146, 149, 153, 156, 160, - /* 40 */ 163, 167, 170, 173, 177, - /* 45 */ 180, 183, 186, 189, 192, - /* 50 */ 195, 198, 200, 203, 206, - /* 55 */ 208, 211, 213, 216, 218, - /* 60 */ 220, 223, 225, 227, 229, - /* 65 */ 231, 232, 234, 236, 238, - /* 70 */ 239, 241, 242, 243, 245, - /* 75 */ 246, 247, 248, 249, 250, - /* 80 */ 251, 251, 252, 253, 253, - /* 85 */ 254, 254, 254, 254, 254, - /* 90 */ 255, 254, 254, 254, 254, - /* 95 */ 254, 253, 253, 252, 251, - /* 100 */ 251, 250, 249, 248, 247, - /* 105 */ 246, 245, 243, 242, 241, - /* 110 */ 239, 238, 236, 234, 232, - /* 115 */ 231, 229, 227, 225, 223, - /* 120 */ 220, 218, 216, 213, 211, - /* 125 */ 208, 206, 203, 200, 198, - /* 130 */ 195, 192, 189, 186, 183, - /* 135 */ 180, 177, 173, 170, 167, - /* 140 */ 163, 160, 156, 153, 149, - /* 145 */ 146, 142, 138, 135, 131, - /* 150 */ 127, 123, 119, 115, 111, - /* 155 */ 107, 103, 99, 95, 91, - /* 160 */ 87, 83, 78, 74, 70, - /* 165 */ 65, 61, 57, 53, 48, - /* 170 */ 44, 39, 35, 31, 26, - /* 175 */ 22, 17, 13, 8, 4, + /* 0 */ 127, 131, 136, 140, 145, + /* 5 */ 149, 154, 158, 162, 166, + /* 10 */ 171, 175, 179, 183, 187, + /* 15 */ 191, 195, 198, 202, 205, + /* 20 */ 209, 212, 216, 219, 222, + /* 25 */ 225, 227, 230, 233, 235, + /* 30 */ 237, 240, 242, 243, 245, + /* 35 */ 247, 248, 250, 251, 252, + /* 40 */ 253, 253, 254, 254, 254, + /* 45 */ 255, 254, 254, 254, 253, + /* 50 */ 253, 252, 251, 250, 248, + /* 55 */ 247, 245, 243, 242, 240, + /* 60 */ 237, 235, 233, 230, 227, + /* 65 */ 225, 222, 219, 216, 212, + /* 70 */ 209, 205, 202, 198, 195, + /* 75 */ 191, 187, 183, 179, 175, + /* 80 */ 171, 166, 162, 158, 154, + /* 85 */ 149, 145, 140, 136, 131, + /* 90 */ 127, 123, 118, 114, 109, + /* 95 */ 105, 100, 96, 92, 88, + /* 100 */ 83, 79, 75, 71, 67, + /* 105 */ 63, 59, 56, 52, 49, + /* 110 */ 45, 42, 38, 35, 32, + /* 115 */ 29, 27, 24, 21, 19, + /* 120 */ 17, 14, 12, 11, 9, + /* 125 */ 7, 6, 4, 3, 2, + /* 130 */ 1, 1, 0, 0, 0, + /* 135 */ 0, 0, 0, 0, 1, + /* 140 */ 1, 2, 3, 4, 6, + /* 145 */ 7, 9, 11, 12, 14, + /* 150 */ 17, 19, 21, 24, 27, + /* 155 */ 29, 32, 35, 38, 42, + /* 160 */ 45, 49, 52, 56, 59, + /* 165 */ 63, 67, 71, 75, 79, + /* 170 */ 83, 88, 92, 96, 100, + /* 175 */ 105, 109, 114, 118, 123, }; From 3d7eeccf1cbdfe5f8fce08320dd03407c004dbf6 Mon Sep 17 00:00:00 2001 From: Jakob Klepp Date: Sat, 13 May 2023 23:07:34 +0200 Subject: [PATCH 3/5] :rainbow: without position awareness --- ownpage-booth/ownpage-booth.ino | 38 +++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/ownpage-booth/ownpage-booth.ino b/ownpage-booth/ownpage-booth.ino index d0043e7..687739d 100644 --- a/ownpage-booth/ownpage-booth.ino +++ b/ownpage-booth/ownpage-booth.ino @@ -200,7 +200,7 @@ const char SINE_WAVEFORM[180] = { // need to define DATA_PIN. For led chipsets that are SPI based (four wires - data, clock, // ground, and power), like the LPD8806 define both DATA_PIN and CLOCK_PIN // Clock pin only needed for SPI based chipsets when not using hardware SPI -#define DATA_PIN 3 +#define DATA_PIN 9 //#define CLOCK_PIN 13 // Define the array of leds @@ -222,7 +222,7 @@ void setup() { // FastLED.addLeds(leds, NUM_LEDS); // FastLED.addLeds(leds, NUM_LEDS); // GRB ordering is typical // FastLED.addLeds(leds, NUM_LEDS); // GRB ordering is typical - FastLED.addLeds(leds, NUM_LEDS); // GRB ordering is typical + FastLED.addLeds(leds, NUM_LEDS); // GRB ordering is typical // FastLED.addLeds(leds, NUM_LEDS); // FastLED.addLeds(leds, NUM_LEDS); // GRB ordering is typical // FastLED.addLeds(leds, NUM_LEDS); @@ -250,13 +250,29 @@ void setup() { // FastLED.addLeds(leds, NUM_LEDS); // BGR ordering is typical } -void loop() { - // Turn the LED on, then pause - leds[0] = CRGB::Red; - FastLED.show(); - delay(500); - // Now turn the LED off, then pause - leds[0] = CRGB::Black; - FastLED.show(); - delay(500); +int t = 0; + +char crude_sin(int x) { + return SINE_WAVEFORM[x % 180]; +} + +//void loop() { +// // Turn the LED on, then pause +// leds[0] = CRGB::Red; +// FastLED.show(); +// delay(500); +// // Now turn the LED off, then pause +// leds[0] = CRGB::Black; +// FastLED.show(); +// delay(500); +//} + +void loop() { + ++t; +// leds[0].setRGB(t % 256, 0, 0); + for (int i = 0; i < NUM_LEDS; ++i) { + leds[i].setRGB(crude_sin(t + i), crude_sin(t + i + 60), crude_sin(t + i + 120)); + } + FastLED.show(); + delay(10); } From 6a50a5b5b1264177fd37bd403820263991bad9d6 Mon Sep 17 00:00:00 2001 From: Jakob Klepp Date: Sat, 13 May 2023 23:12:31 +0200 Subject: [PATCH 4/5] This should take x-coord for each LED into account --- ownpage-booth/ownpage-booth.ino | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ownpage-booth/ownpage-booth.ino b/ownpage-booth/ownpage-booth.ino index 687739d..6223678 100644 --- a/ownpage-booth/ownpage-booth.ino +++ b/ownpage-booth/ownpage-booth.ino @@ -268,11 +268,13 @@ char crude_sin(int x) { //} void loop() { + int x = 0; ++t; // leds[0].setRGB(t % 256, 0, 0); for (int i = 0; i < NUM_LEDS; ++i) { - leds[i].setRGB(crude_sin(t + i), crude_sin(t + i + 60), crude_sin(t + i + 120)); + x = POSITION_MAP[i].x / 3; + leds[i].setRGB(crude_sin(t + x), crude_sin(t + x + 60), crude_sin(t + x + 120)); } FastLED.show(); - delay(10); + delay(20); } From 0156cf6ac5e999720cedb47143a747077fe95ea6 Mon Sep 17 00:00:00 2001 From: Jakob Klepp Date: Sat, 13 May 2023 23:13:18 +0200 Subject: [PATCH 5/5] Cleanup --- ownpage-booth/ownpage-booth.ino | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/ownpage-booth/ownpage-booth.ino b/ownpage-booth/ownpage-booth.ino index 6223678..c77af5d 100644 --- a/ownpage-booth/ownpage-booth.ino +++ b/ownpage-booth/ownpage-booth.ino @@ -256,21 +256,10 @@ char crude_sin(int x) { return SINE_WAVEFORM[x % 180]; } -//void loop() { -// // Turn the LED on, then pause -// leds[0] = CRGB::Red; -// FastLED.show(); -// delay(500); -// // Now turn the LED off, then pause -// leds[0] = CRGB::Black; -// FastLED.show(); -// delay(500); -//} void loop() { int x = 0; ++t; -// leds[0].setRGB(t % 256, 0, 0); for (int i = 0; i < NUM_LEDS; ++i) { x = POSITION_MAP[i].x / 3; leds[i].setRGB(crude_sin(t + x), crude_sin(t + x + 60), crude_sin(t + x + 120));