clean leds

This commit is contained in:
Lurkars 2020-12-30 23:04:08 +01:00
parent 34a646d16e
commit 2e2d165c62
2 changed files with 19 additions and 14 deletions

View File

@ -39,7 +39,7 @@
let canvas_out_elem = document.getElementById("canvas_out"); let canvas_out_elem = document.getElementById("canvas_out");
let canvas_out2_elem = document.getElementById("canvas_out2"); let canvas_out2_elem = document.getElementById("canvas_out2");
// helper for printing number as hex value
let intToHex = function (color, int16) { let intToHex = function (color, int16) {
let text = color.toString(16); let text = color.toString(16);
@ -64,8 +64,8 @@
let canvas_context = canvas_elem.getContext("2d"); let canvas_context = canvas_elem.getContext("2d");
canvas_context.drawImage(image, 0, 0); canvas_context.drawImage(image, 0, 0);
const num_segments = num_segments_elem.value; const num_segments = parseInt(num_segments_elem.value);
const num_leds = num_leds_elem.value; const num_leds = parseInt(num_leds_elem.value);
const led_offset = Math.floor(led_offset_elem.value); const led_offset = Math.floor(led_offset_elem.value);
const offset_x = image.width / 2; const offset_x = image.width / 2;
@ -76,7 +76,7 @@
let canvas_out_context = canvas_out_elem.getContext("2d"); let canvas_out_context = canvas_out_elem.getContext("2d");
canvas_out_elem.width = image.width; canvas_out_elem.width = image.width;
canvas_out_elem.height = image.height; canvas_out_elem.height = image.height;
let out_data = canvas_out_context.createImageData(image.width, image.height); let out_data = canvas_out_context.createImageData(canvas_out_elem.width, canvas_out_elem.height);
let canvas_out2_context = canvas_out2_elem.getContext("2d"); let canvas_out2_context = canvas_out2_elem.getContext("2d");
@ -88,17 +88,16 @@
for (let led = 0; led < num_leds; led++) { for (let led = 0; led < num_leds; led++) {
for (let seg = 0; seg < num_segments; seg++) { for (let seg = 0; seg < num_segments; seg++) {
let x = offset_x + (led_offset + led) * Math.cos((seg * (1 / num_segments) * 360) * (Math.PI / 180)); let x = Math.floor(offset_x + (led_offset + led) * Math.cos((seg * (1 / num_segments) * 360) * (Math.PI / 180)));
let y = offset_y + (led_offset + led) * Math.sin((seg * (1 / num_segments) * 360) * (Math.PI / 180)); let y = Math.floor(offset_y + (led_offset + led) * Math.sin((seg * (1 / num_segments) * 360) * (Math.PI / 180)));
if (!data[seg]) { if (!data[seg]) {
data[seg] = new Array(); data[seg] = new Array();
} }
// data[seg][led] = Math.floor(x) + ":" + Math.floor(y); data[seg][led] = canvas_context.getImageData(x, y, 1, 1).data;
data[seg][led] = canvas_context.getImageData(Math.floor(x), Math.floor(y), 1, 1).data;
for (let i = 0; i < 3; i++) { for (let i = 0; i < 3; i++) {
data[seg][led][i] = data[seg][led][i] - (data[seg][led][i] % 32); data[seg][led][i] = data[seg][led][i] - (data[seg][led][i] % 32);
} }
let index = 4 * (Math.floor(x) + Math.floor(y) * image.width); let index = 4 * (x + y * canvas_out_elem.width);
out_data.data[index] = data[seg][led][0]; out_data.data[index] = data[seg][led][0];
out_data.data[index + 1] = data[seg][led][1]; out_data.data[index + 1] = data[seg][led][1];
out_data.data[index + 2] = data[seg][led][2]; out_data.data[index + 2] = data[seg][led][2];

View File

@ -67,6 +67,12 @@ void setup()
ledStrip.begin(); ledStrip.begin();
ledStrip.show(); ledStrip.show();
ledStrip.setBrightness(BRIGHTNESS); ledStrip.setBrightness(BRIGHTNESS);
#else
for (int i = 0; i < LED_COUNT * 4; i++) // loop over all LEDs
{
color_buffer[i] = rgb_color(0, 0, 0); // set to black
}
ledStrip.write(color_buffer, LED_COUNT * LED_STRIPES, 0); // write buffer to stripes
#endif #endif
} }