Compare commits

...

5 commits

Author SHA1 Message Date
Jakob Klepp
0156cf6ac5 Cleanup 2023-05-13 23:13:18 +02:00
Jakob Klepp
6a50a5b5b1 This should take x-coord for each LED into account 2023-05-13 23:12:31 +02:00
Jakob Klepp
3d7eeccf1c 🌈 without position awareness 2023-05-13 23:07:34 +02:00
Jakob Klepp
983ea347d1 Generate full periode 2023-05-12 20:55:23 +02:00
Jakob Klepp
8a2c070e63 Var name 2023-05-12 20:47:47 +02:00
2 changed files with 58 additions and 52 deletions

View file

@ -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,14 +8,14 @@ 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) {
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 += `

View file

@ -153,44 +153,43 @@ const struct led_position POSITION_MAP[144] = {
/* 143 */ { 285.816650390625, 47.65000915527344 },
};
const char[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,
const char SINE_WAVEFORM[180] = {
/* 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,
};
@ -201,7 +200,7 @@ const char[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
@ -223,7 +222,7 @@ void setup() {
// FastLED.addLeds<UCS2903, DATA_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<WS2812, DATA_PIN, RGB>(leds, NUM_LEDS); // GRB ordering is typical
// FastLED.addLeds<WS2852, DATA_PIN, RGB>(leds, NUM_LEDS); // GRB ordering is typical
FastLED.addLeds<WS2812B, DATA_PIN, RGB>(leds, NUM_LEDS); // GRB ordering is typical
FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS); // GRB ordering is typical
// FastLED.addLeds<GS1903, DATA_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<SK6812, DATA_PIN, RGB>(leds, NUM_LEDS); // GRB ordering is typical
// FastLED.addLeds<SK6822, DATA_PIN, RGB>(leds, NUM_LEDS);
@ -251,13 +250,20 @@ void setup() {
// FastLED.addLeds<SK9822, DATA_PIN, CLOCK_PIN, RGB>(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() {
int x = 0;
++t;
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));
}
FastLED.show();
delay(20);
}