Hallo Zusammen,
folgender kleiner Sketch ist bei mir extrem langsam... Ich sehe aber keinen Fehler. Das Empfangen vie nrf24 läuft reibungslos.... aber das Ansteuern der LEDs ist extrem langsam. Bis alle LEDs eine neue Farbe übernommen haben vergeht gut 1 Sekunde bei 162 LEDs...
Ich hatte den selben Sketch auch auf einen Teensy LC, da geht alles schön flüßig... Aber andere Fast-LED Projekte waren bisher auch auf dem nano richtig flott....
#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"
#include "printf.h"
#include "FastLED.h"
#define NUM_LEDS 162 //TVrechts = 162, TVlinks = 224, Fenster = 236
#define DATA_PIN 2
CRGB leds[NUM_LEDS];
RF24 radio(9,10); // (CE, CSN)
byte addresses[][6] = {"1Node", "2Node", "3Node", "4Node", "5Node", "6Node"};
byte Sensor[9];
byte fade;
byte Farbe1[3];
byte Farbe2[3];
byte FarbeIst1[3];
byte FarbeIst2[3];
unsigned long AusTimer;
const unsigned long AusZeit = 3000;
unsigned long TimerNaechsterSchritt;
const unsigned long NaechsterSchritt = 1;
void setup()
{
Serial.begin(9600);
Serial.print("Test Empfang");
radio.begin();
radio.openWritingPipe((byte*)"2Node");
radio.openReadingPipe(1, (byte*)"1Node");
radio.setRetries(15,15);
//radio.setPALevel(RF24_PA_MIN);
//radio.setDataRate(RF24_1MBPS);
radio.startListening();
radio.printDetails();
LEDS.addLeds<WS2812,DATA_PIN,RGB>(leds,NUM_LEDS);
LEDS.setBrightness(255);
}
void loop()
{
if (radio.available()) {
radio.read( Sensor, sizeof(Sensor) );
//EmpfangsInfos();
AusTimer = millis();
memcpy(Farbe2, Sensor+2, 3);
memcpy(Farbe1, Sensor+5, 3);
// Serial.println(" kein Empfang ");
}
Serial.println(millis() - AusTimer);
if ( millis() - AusTimer > AusZeit && millis() - AusTimer < AusZeit + 20 )
{
Farbe1[0] = 0;
Farbe1[1] = 0;
Farbe1[2] = 0;
Farbe2[0] = 0;
Farbe2[1] = 0;
Farbe2[2] = 0;
//Serial.println(" schalte den Streifen aus ");
}
if ( micros() - TimerNaechsterSchritt > NaechsterSchritt )
{ TimerNaechsterSchritt = millis();
if ( Farbe1[0] > FarbeIst1[0] ) { FarbeIst1[0]++; }
if ( Farbe1[1] > FarbeIst1[1] ) { FarbeIst1[1]++; }
if ( Farbe1[2] > FarbeIst1[2] ) { FarbeIst1[2]++; }
if ( Farbe2[0] > FarbeIst2[0] ) { FarbeIst2[0]++; }
if ( Farbe2[1] > FarbeIst2[1] ) { FarbeIst2[1]++; }
if ( Farbe2[2] > FarbeIst2[2] ) { FarbeIst2[2]++; }
if ( Farbe1[0] < FarbeIst1[0] ) { FarbeIst1[0]--; }
if ( Farbe1[1] < FarbeIst1[1] ) { FarbeIst1[1]--; }
if ( Farbe1[2] < FarbeIst1[2] ) { FarbeIst1[2]--; }
if ( Farbe2[0] < FarbeIst2[0] ) { FarbeIst2[0]--; }
if ( Farbe2[1] < FarbeIst2[1] ) { FarbeIst2[1]--; }
if ( Farbe2[2] < FarbeIst2[2] ) { FarbeIst2[2]--; }
}
//fill_gradient_RGB(leds,NUM_LEDS,CRGB(FarbeIst2[1],FarbeIst2[0],FarbeIst2[2]),0,CRGB(FarbeIst1[1],FarbeIst1[0],FarbeIst1[1])); FastLED.show();
for(int i = 0; i < NUM_LEDS; i++)
{
leds[i] = CRGB(((Farbe1[0]*(NUM_LEDS - i)) + Farbe2[0] * i)/NUM_LEDS,((Farbe1[1]*(NUM_LEDS - i)) + Farbe2[1] * i)/NUM_LEDS,((Farbe1[2]*(NUM_LEDS - i)) + Farbe2[2] * i)/NUM_LEDS);
FastLED.show();
}
Serial.println("Farben: ");
Serial.print(Farbe1[0]);
Serial.print(" / ");
Serial.print(Farbe1[1]);
Serial.print(" / ");
Serial.print(Farbe1[2]);
Serial.print(" - ");
Serial.print(Farbe2[0]);
Serial.print(" / ");
Serial.print(Farbe2[1]);
Serial.print(" / ");
Serial.println(Farbe2[2]);
}