Apologies for misunderstanding your question ... 😉
Note: I've added your video (converted it with Handbrake to a smaller file and removed the audio) to your post as an attachment (so you can remove it from your Google Drive). I hope you don't mind.
Alrighty, let me go through the code, assuming you're having just one red block moving at a time.
If you want to have multiple red blocks running, things will have to change a litte, and then I'd definitely switch over to FastLED. I'd recommend using FastLED over NeoPixel, since FastLED is more mature and has better support for special stuff. I'll continue assuming you'll keep using NeoPixel though.
1.Define NUM_LEDS ...
I'd define the number of LEDs as a constant (to be entirely correct: #define is not really a constant, it's a compiler directive to replace all "NUM_LEDS" with 150 just before compiling). So instead of typing 150 (so called "magic number") each time I'd use something like NUM_LEDS. This will make adjusting the code in the future easier (if you decide to use a longer or shorter strip) and it makes the code easier to read.
#define NUM_LEDS 150
...
Adafruit_NeoPixel tira = Adafruit_NeoPixel(NUM_LEDS, 6, NEO_GRB + NEO_KHZ800); // creacion de objeto “tira”
...
2. To get multiple red blocks ...
This can a be a little tricky ... I'd draw 20 red leds when the sensor gets triggered, and after that keep moving the leds to the right, even if they are all green.
So when triggered, first draw a red block, for example with a function like this:
void DrawRedBlock()
{
for(int Counter=0; Counter<20; Counter++)
{
tira.setPixelColor(Counter, 255, 0, 0);
tire.show();
}
}
While waiting for input, I'd keep doing this endlessly:
// Move all LEDs one position
for(int Counter=NUM_LEDS-1; Counter>0; Counter--)
{
tira.showPixelColor( Counter, getPixelColor( Counter-1 ));
tira.show();
}
// add one green LED at the beginning
tira.setPixelColor(0, 0, 255, 0);
tira.show();
This should move the existing colors one LED up, byt copying the color from the previous LED to the current LED.
I'm counting backwards to avoid overwriting a LED color before reading it's value.
So we the color of LED 148 -> LED 149, LED 147 -> LED 148, LED 146 -> LED 146, etc.
Note: I do not use NeoPixel anymore, so I had to dig into the documentation to (hopefully) find the correct function for reading the LED color. FastLED works much easier when it comes to "animation" like this. Moving all the LEDs can be done in one single line.
So all together:
1. Fill the strip with green LEDs (you already have code for that)
2. When the sensor gets triggered draw a red block at the beginning, one LED at a time.
3. While waiting for input keep shifting the LEDs one position.
Now the remaining piece of the puzzle is reading the sensor in a timely fashion.
In one of my projects I've done this by replacing the tira.show() function with one of my own so it reads the sensor very often.
Something like this:
void showstrip()
{
// Read sensor
estado1=digitalRead(pinsensor1);
// if sensor is LOW then draw the red block and finish drawing it before proceeding
if(estado1==LOW)
{
DrawRedBlock();
}
tira.show();
}
And in the loop to move the LEDs, we can do something like this:
// Move all LEDs one position
for(int Counter=NUM_LEDS-1; Counter>0; Counter--)
{
tira.showPixelColor( Counter, getPixelColor( Counter-1 ));
showstrip(); // was: tira.show();
}
// add one green LED at the beginning
tira.setPixelColor(0, 0, 255, 0);
showstrip(); // was: tira.show();
Now, each time we "show" the strip, we also test the sensor.
Hope this is helpful - and again: I have not tested the code.