Vinz68 / NeoPixel-Stair

Stair LedLights, using NeoPixel Ledstrips and an Arduino
9 stars 1 forks source link

Differing Stair widths? #8

Closed GrizLee closed 2 years ago

GrizLee commented 3 years ago

Is it possible to modify this code for different stair widths? (I have stairs that go straight for a couple of steps and then do a 180, so the one "in the curve" are wider), if there would be a possibility of entering LED per row Define row1 45 define row2 20

etc

Vinz68 commented 2 years ago

Hi GrizLee, sorry for my late response. It is possible to change the code to fulfill your request. Maybe you already succeed in changing the code, but here some tips: I would keep the variable "LEDSTRIPS" , which is the number of stairs And then change the functions "colourWipeDown" and "colourWipeDown" which actually turns the leds on and off. I would make an array of size LEDSTRIPS, and each array element is of a new type (myStairType) which has a start-led nr, and a width (size of that stair). So add something like this at the variable definition:

typedef struct { int start; int width; } myStairType;

myStairType stairs[LEDSTRIPS];

Then in the setup, fill the array: stairs[0] = (myStairType) {0, 45}; stairs[1] = (myStairType) {45, 20}; stairs[2] = (myStairType) {65, 20}; ... and so on.

In the functions you have to replace some code in the loop:

In colourWipeDown, replace this original code: int start = (NUMPIXELS/LEDSTRIPS) *k;

with: int start = stairs[k].start

and this for (uint16_t j = start; j < start + LEDSPERSTRIP; j++){ strip.setPixelColor(j, c);

with: for (uint16_t j = start; j < start + stairs[k].width; j++){ strip.setPixelColor(j, c);

In colourWipeUp, replace this original code: int start = NUMPIXELS/LEDSTRIPS *k; int x = start;

with int x= stairs[k].start + starts[k].width

and this do { strip.setPixelColor(x-1, c); x--; } while (x > start - LEDSPERSTRIP);

with this do { strip.setPixelColor(x-1, c); x--; } while (x > stairs[k].start);

I would alo make the handleBreathe function empty ( { } ) ; this can be fixed later when needed.

I hope this helps. very best regards, Vincent.