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 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 ();
.....
}