you nested the loops instead of creating two separate loops
this may be easier to understand, i separated out the common code in setLedColor()
/* ************************************
Schematic for this sketch at
Architectural_lights/Strip Lights/WS2812b/SAMD21_to_WS2812b_w_PIR_schematic_250723.jpg
PIR_to_SAMD21_to_WS28212b_250725.ino
combines
PIR sensor code from
PIR_to_Arduino_250725.ino
with PIR digitalRead code from
Staircase_Single_Channel_PIR_to_LED_220424.ino
with WS28212b code from
WS2812b_Fade_Color_to_Color_250722.ino
************************************ */
#include "FastLED.h"
#define DATA_PIN 4
#define NUM_LEDS 299
#define COLOR_ORDER GRB
CRGB leds[NUM_LEDS];
void setup() {
FastLED.addLeds<WS2811, DATA_PIN, GRB>(leds, NUM_LEDS);
FastLED.setBrightness(84);
pinMode(2, INPUT); //Pin 2 as INPUT
}
void fadeall() {
for(int i = 0; i < NUM_LEDS; i++)
leds[i].nscale8(250);
}
void loop() {
if (digitalRead(2) == HIGH)
runSAMD21();
}
void setLedColor (
int colorStep )
{
int r = colorStep; // Redness starts at zero and goes up to full
int b = 255-colorStep; // Blue starts at full and goes down to zero
int g = 0; // No green needed to go from blue to red
// Now loop though each of the LEDs and set each one to the current color
for(int x = 0; x < NUM_LEDS; x++)
leds[x] = CRGB(r,g,b);
FastLED.show();
delay(10);
}
void runSAMD21(){
// 256 steps to get from blue to red
// (the most possible with an LED with 8 bit RGB values)
for( int colorStep=0; colorStep<256; colorStep++)
setLedColor (colorStep);
for( int colorStep=256; colorStep>0; colorStep--)
setLedColor (colorStep);
}