clean leds
This commit is contained in:
parent
34a646d16e
commit
2e2d165c62
@ -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];
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
// Copyright 2020 Lukas Haubaum
|
// Copyright 2020 Lukas Haubaum
|
||||||
//
|
//
|
||||||
// Licensed under MIT license
|
// Licensed under MIT license
|
||||||
//
|
//
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
@ -31,8 +31,8 @@
|
|||||||
#define LED_COUNT 26 // how many LEDs on one stripe
|
#define LED_COUNT 26 // how many LEDs on one stripe
|
||||||
#define LED_STRIPES 2 // how many LEDs stripes on wheel
|
#define LED_STRIPES 2 // how many LEDs stripes on wheel
|
||||||
|
|
||||||
int strip_matrix_offset[LED_STRIPES] = {0, 0}; // given offset in segments for stripe
|
int strip_matrix_offset[LED_STRIPES] = {0, 0}; // given offset in segments for stripe
|
||||||
bool strip_matrix_invert[LED_STRIPES] = {false, true}; // set LEDs in revert order for stripe
|
bool strip_matrix_invert[LED_STRIPES] = {false, true}; // set LEDs in revert order for stripe
|
||||||
// \CONFIGURE
|
// \CONFIGURE
|
||||||
|
|
||||||
// LED stripes
|
// LED stripes
|
||||||
@ -44,8 +44,8 @@ Adafruit_NeoPixel ledStrip(LED_COUNT *LED_STRIPES, LED_PIN, NEO_GRB + NEO_KHZ800
|
|||||||
#define LED_DATA_PIN 3 // data pin for LED strip
|
#define LED_DATA_PIN 3 // data pin for LED strip
|
||||||
#define LED_CLOCK_PIN 2 // clock pin for LED strip
|
#define LED_CLOCK_PIN 2 // clock pin for LED strip
|
||||||
APA102<LED_DATA_PIN, LED_CLOCK_PIN> ledStrip;
|
APA102<LED_DATA_PIN, LED_CLOCK_PIN> ledStrip;
|
||||||
#define BRIGHTNESS 1 // brightness for LED strip [0-31]
|
#define BRIGHTNESS 1 // brightness for LED strip [0-31]
|
||||||
rgb_color color_buffer[LED_COUNT * LED_STRIPES]; // color buffer to write to LED stripe
|
rgb_color color_buffer[LED_COUNT * LED_STRIPES]; // color buffer to write to LED stripe
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
float passed = 0;
|
float passed = 0;
|
||||||
@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user