Compare commits

..

No commits in common. "0156cf6ac5e999720cedb47143a747077fe95ea6" and "1a44ae2e4b7eb0da026f3cf6e10f9707d24b9bc0" have entirely different histories.

2 changed files with 51 additions and 57 deletions

View file

@ -1,4 +1,4 @@
/* Crude approximation of a sine wave /* 180 step waveform approximation for a sine wave with amplitude 255
node gen_wave_form.js node gen_wave_form.js
@ -8,14 +8,14 @@ Or paste in browser developer console.
const steps = 180; const steps = 180;
let output = ` let output = `
const char SINE_WAVEFORM[${steps}] = {`; const char[${steps}] = {`;
for (let i = 0; i < steps; i++) { for (let i = 0; i < steps; i++) {
if (i % 5 === 0) { if (i % 5 === 0) {
output += ` output += `
/* ${i} */` /* ${i} */`
} }
output += ` ${Math.floor(255 * (1 + Math.sin(2 * Math.PI / steps * i)) / 2)},`; output += ` ${Math.floor(255 * Math.sin(Math.PI / steps * i))},`;
} }
output += ` output += `

View file

@ -153,43 +153,44 @@ const struct led_position POSITION_MAP[144] = {
/* 143 */ { 285.816650390625, 47.65000915527344 }, /* 143 */ { 285.816650390625, 47.65000915527344 },
}; };
const char SINE_WAVEFORM[180] = {
/* 0 */ 127, 131, 136, 140, 145, const char[180] = {
/* 5 */ 149, 154, 158, 162, 166, /* 0 */ 0, 4, 8, 13, 17,
/* 10 */ 171, 175, 179, 183, 187, /* 5 */ 22, 26, 31, 35, 39,
/* 15 */ 191, 195, 198, 202, 205, /* 10 */ 44, 48, 53, 57, 61,
/* 20 */ 209, 212, 216, 219, 222, /* 15 */ 65, 70, 74, 78, 83,
/* 25 */ 225, 227, 230, 233, 235, /* 20 */ 87, 91, 95, 99, 103,
/* 30 */ 237, 240, 242, 243, 245, /* 25 */ 107, 111, 115, 119, 123,
/* 35 */ 247, 248, 250, 251, 252, /* 30 */ 127, 131, 135, 138, 142,
/* 40 */ 253, 253, 254, 254, 254, /* 35 */ 146, 149, 153, 156, 160,
/* 45 */ 255, 254, 254, 254, 253, /* 40 */ 163, 167, 170, 173, 177,
/* 50 */ 253, 252, 251, 250, 248, /* 45 */ 180, 183, 186, 189, 192,
/* 55 */ 247, 245, 243, 242, 240, /* 50 */ 195, 198, 200, 203, 206,
/* 60 */ 237, 235, 233, 230, 227, /* 55 */ 208, 211, 213, 216, 218,
/* 65 */ 225, 222, 219, 216, 212, /* 60 */ 220, 223, 225, 227, 229,
/* 70 */ 209, 205, 202, 198, 195, /* 65 */ 231, 232, 234, 236, 238,
/* 75 */ 191, 187, 183, 179, 175, /* 70 */ 239, 241, 242, 243, 245,
/* 80 */ 171, 166, 162, 158, 154, /* 75 */ 246, 247, 248, 249, 250,
/* 85 */ 149, 145, 140, 136, 131, /* 80 */ 251, 251, 252, 253, 253,
/* 90 */ 127, 123, 118, 114, 109, /* 85 */ 254, 254, 254, 254, 254,
/* 95 */ 105, 100, 96, 92, 88, /* 90 */ 255, 254, 254, 254, 254,
/* 100 */ 83, 79, 75, 71, 67, /* 95 */ 254, 253, 253, 252, 251,
/* 105 */ 63, 59, 56, 52, 49, /* 100 */ 251, 250, 249, 248, 247,
/* 110 */ 45, 42, 38, 35, 32, /* 105 */ 246, 245, 243, 242, 241,
/* 115 */ 29, 27, 24, 21, 19, /* 110 */ 239, 238, 236, 234, 232,
/* 120 */ 17, 14, 12, 11, 9, /* 115 */ 231, 229, 227, 225, 223,
/* 125 */ 7, 6, 4, 3, 2, /* 120 */ 220, 218, 216, 213, 211,
/* 130 */ 1, 1, 0, 0, 0, /* 125 */ 208, 206, 203, 200, 198,
/* 135 */ 0, 0, 0, 0, 1, /* 130 */ 195, 192, 189, 186, 183,
/* 140 */ 1, 2, 3, 4, 6, /* 135 */ 180, 177, 173, 170, 167,
/* 145 */ 7, 9, 11, 12, 14, /* 140 */ 163, 160, 156, 153, 149,
/* 150 */ 17, 19, 21, 24, 27, /* 145 */ 146, 142, 138, 135, 131,
/* 155 */ 29, 32, 35, 38, 42, /* 150 */ 127, 123, 119, 115, 111,
/* 160 */ 45, 49, 52, 56, 59, /* 155 */ 107, 103, 99, 95, 91,
/* 165 */ 63, 67, 71, 75, 79, /* 160 */ 87, 83, 78, 74, 70,
/* 170 */ 83, 88, 92, 96, 100, /* 165 */ 65, 61, 57, 53, 48,
/* 175 */ 105, 109, 114, 118, 123, /* 170 */ 44, 39, 35, 31, 26,
/* 175 */ 22, 17, 13, 8, 4,
}; };
@ -200,7 +201,7 @@ const char SINE_WAVEFORM[180] = {
// need to define DATA_PIN. For led chipsets that are SPI based (four wires - data, clock, // 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 // 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 // Clock pin only needed for SPI based chipsets when not using hardware SPI
#define DATA_PIN 9 #define DATA_PIN 3
//#define CLOCK_PIN 13 //#define CLOCK_PIN 13
// Define the array of leds // Define the array of leds
@ -222,7 +223,7 @@ void setup() {
// FastLED.addLeds<UCS2903, DATA_PIN, RGB>(leds, NUM_LEDS); // FastLED.addLeds<UCS2903, DATA_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<WS2812, DATA_PIN, RGB>(leds, NUM_LEDS); // GRB ordering is typical // 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<WS2852, 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<WS2812B, DATA_PIN, RGB>(leds, NUM_LEDS); // GRB ordering is typical
// FastLED.addLeds<GS1903, DATA_PIN, RGB>(leds, NUM_LEDS); // FastLED.addLeds<GS1903, DATA_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<SK6812, DATA_PIN, RGB>(leds, NUM_LEDS); // GRB ordering is typical // FastLED.addLeds<SK6812, DATA_PIN, RGB>(leds, NUM_LEDS); // GRB ordering is typical
// FastLED.addLeds<SK6822, DATA_PIN, RGB>(leds, NUM_LEDS); // FastLED.addLeds<SK6822, DATA_PIN, RGB>(leds, NUM_LEDS);
@ -250,20 +251,13 @@ void setup() {
// FastLED.addLeds<SK9822, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS); // BGR ordering is typical // FastLED.addLeds<SK9822, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS); // BGR ordering is typical
} }
int t = 0;
char crude_sin(int x) {
return SINE_WAVEFORM[x % 180];
}
void loop() { void loop() {
int x = 0; // Turn the LED on, then pause
++t; leds[0] = CRGB::Red;
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(); FastLED.show();
delay(20); delay(500);
// Now turn the LED off, then pause
leds[0] = CRGB::Black;
FastLED.show();
delay(500);
} }