Need help, ws2812b led stairs and 2 motion sensors,dynamic memory used

I use all dynamic memory when i put all leds(pixels),when i put 500,600 hundred it works,i have 1020 leds in whole stairs,is there any way to use less memory? Had some problems with sensors so i used their function to make them work faster and as delay in other functions,i know it looks bad :confused: Here is my code

/* HC-SR04 Sensor (ultrasonic)
 https://www.dealextreme.com/p/hc-sr04-ultrasonic-sensor-distance-measuring-module-133696
 
 This sketch reads a HC-SR04 ultrasonic rangefinder and returns the
 distance to the closest object in range. To do this, it sends a pulse
 to the sensor to initiate a reading, then listens for a pulse 
 to return.  The length of the returning pulse is proportional to 
 the distance of the object from the sensor.
 
 The circuit:
 * VCC connection of the sensor attached to +5V
 * GND connection of the sensor attached to ground
 * TRIG connection of the sensor attached to digital pin 2
 * ECHO connection of the sensor attached to digital pin 4
 Original code for Ping))) example was created by David A. Mellis
 Adapted for HC-SR04 by Tautvidas Sipavicius
 This example code is in the public domain.
 */
#include <Ultrasonic.h>
Ultrasonic ultrasonic(2, 4);

//LEDs
#include "FastLED.h"

// How many leds in your strip?
#define NUM_LEDS 1020
#define BRIGHTNESS          50

// For led chips like Neopixels, which have a data line, ground, and power, you just
// need to define DATA_PIN.  For led chipsets that are SPI based (four wires - data, clock,
// ground, and power), like the LPD8806 define both DATA_PIN and CLOCK_PIN
#define DATA_PIN 5
// Define the array of leds
CRGB leds[NUM_LEDS];

void setup() { 
  FastLED.addLeds<WS2812B, DATA_PIN, RGB>(leds, NUM_LEDS);
    FastLED.setBrightness(BRIGHTNESS);
  // ultrasonic sensor
  // initialize serial communication:   
  Serial.begin(9600);
}

 void loop() { 
        senzor ();
    if(ultrasonic.distanceRead() > 5 && ultrasonic.distanceRead() <= 30) {
    // Turn the LED on
  LEDonup ();
  // Turn the LED off
  LEDoffup ();
 }
  else if(ultrasonic.distanceRead() > 31 && ultrasonic.distanceRead() <= 600) {
    // Turn the LED on
    LEDondown ();
    // Turn the LED off
    LEDoffdown ();
 }
 }
void senzor () {
      // ultrasonic sensor
  // establish variables for duration of the ping, 
  // and the distance result in inches and centimeters:
 Serial.print("Distance in CM: ");
  // Pass INC as a parameter to get the distance in inches
  Serial.println(ultrasonic.distanceRead());
  delay(200);
}
void LEDonup () {
  for(int i=0; i<60; i++)
   leds[i] = CRGB::LightSlateGray;
   FastLED.show();
   senzor ();
      senzor ();
         senzor ();
            senzor ();
               senzor ();
     for(int i=60; i<120; i++)
   leds[i] = CRGB::LightSlateGray;
   FastLED.show();
   senzor ();
      senzor ();
         senzor ();
            senzor ();
               senzor ();
....

void LEDondown () {
   for(int i=960; i<1020; i++)
   leds[i] = CRGB::LightSlateGray;
   FastLED.show();
     senzor ();
      senzor ();
         senzor ();
            senzor ();
               senzor ();
     for(int i=900; i<960; i++)
   leds[i] = CRGB::LightSlateGray;
   FastLED.show();
  senzor ();
      senzor ();
         senzor ();
            senzor ();
               senzor ();
    for(int i=840; i<900; i++)
   leds[i] = CRGB::LightSlateGray;
   FastLED.show();
  senzor ();
      senzor ();
         senzor ();
            senzor ();
               senzor ();
     for(int i=780; i<840; i++)
   leds[i] = CRGB::LightSlateGray;
   FastLED.show();
  senzor ();
      senzor ();
         senzor ();
            senzor ();
               senzor ();
    for(int i=720; i<780; i++)
   leds[i] = CRGB::LightSlateGray;
   FastLED.show();
  senzor ();
      senzor ();
         senzor ();
            senzor ();
               senzor ();
     for(int i=660; i<720; i++)
   leds[i] = CRGB::LightSlateGray;
   FastLED.show();
  senzor ();
      senzor ();
         senzor ();
            senzor ();
               senzor ();
.....

void LEDoffdown () {
   for(int i=960; i<1020; i++)
   leds[i] = CRGB(0,0,0); 
   FastLED.show();
  senzor ();
      senzor ();
         senzor ();
            senzor ();
               senzor ();
     for(int i=900; i<960; i++)
   leds[i] = CRGB(0,0,0); 
   FastLED.show();
  senzor ();
      senzor ();
         senzor ();
            senzor ();
               senzor ();
    for(int i=840; i<900; i++)
   leds[i] = CRGB(0,0,0); 
   FastLED.show();
  senzor ();
      senzor ();
         senzor ();
            senzor ();
               senzor ();
.....
   }

As far as I know not with excising library. And I doubt you can ever make it work with less memory because Neopixels are pretty tight on there timing. So you need to have all data ready when you want to send it, no way to pause the data to do some calculation and memory shuffling in between.

So then just use a micro with more memory. No idea what you use now...

You need 3 bytes of memory for each LED so for your 1020 LEDs that is 3060 bytes of memory. As the Uno only has 2K of memory you are never going to control all of them on a Uno.
You need an Arduino with more memory like the Mega, that has 8K of memory. Also a Due or Zero will have enough as well but they are 3V3 devices so you might need a buffer to drive your LEDs with a 5V signal.

septillion:
So then just use a micro with more memory.

The Arduino Micro has only:-
SRAM 2.5 KB (ATmega32U4)

So not enough memory.

micro as in short for micro controller. Not Arduino Micro (which I would at least write with a capital :stuck_out_tongue: )

Thank you all guys i will try with Arduino Mega in couple days,will get you informed

I got my Arduino Mega,code can be uploaded now,and it kind of works,but I have problems with distance sensors now,i am using two jsn sr04t sensors,one is close to controller and it works but not reliable,and other is far so i had to use utp cable to wire it,and it doesn't work at all,when i try with hc sr04 it works great,so i can advise you to buy cheaper and better distance sensor,and that would be hc sr04