/* OctoWS2811 BasicTest.ino - Basic RGB LED Test
http://www.pjrc.com/teensy/td_libs_OctoWS2811.html
Copyright (c) 2013 Paul Stoffregen, PJRC.COM, LLC
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
Required Connections
--------------------
pin 2: LED Strip #1 OctoWS2811 drives 8 LED Strips.
pin 14: LED strip #2 All 8 are the same length.
pin 7: LED strip #3
pin 8: LED strip #4 A 100 ohm resistor should used
pin 6: LED strip #5 between each Teensy pin and the
pin 20: LED strip #6 wire to the LED strip, to minimize
pin 21: LED strip #7 high frequency ringining & noise.
pin 5: LED strip #8
pin 15 & 16 - Connect together, but do not use
pin 4 - Do not use
pin 3 - Do not use as PWM. Normal use is ok.
This test is useful for checking if your LED strips work, and which
color config (WS2811_RGB, WS2811_GRB, etc) they require.
*/
#include <OctoWS2811.h>
#include <SD.h>
#include <SPI.h>
//#include <Bounce.h>
//Timings for apa106
#define WS2811_TIMING_T0H 28
#define WS2811_TIMING_T1H 109
#define WS2811_TIMING_T0L 109
#define WS2811_TIMING_T1L 28
//Filename of colors on SD Card
File myFile;
//Number of LEDs per strip/total
const float MaximumVorticityToShow = 9;
const int NumberOfLEDs = 1600;
const int ledsPerStrip = 200 ;
const int chipSelect = BUILTIN_SDCARD; //Teensy 3.5/3.6 SD-Card
const int FPS = 25;
const int FrameTime = 1000 / FPS; //in MS
const int TotalNumberOfFrames = 24360; //Number of rows in file
const String CurrentFilename = "v.csv";
elapsedMillis ElapsedTimeInMS;
DMAMEM int displayMemory[ledsPerStrip * 6];
int drawingMemory[ledsPerStrip * 6];
//Configuration of APA106 LEDs: RGB, 800Khz
const int config = WS2811_RGB | WS2811_800kHz;
//initialize OctoWS2811
OctoWS2811 leds(ledsPerStrip, displayMemory, drawingMemory, config);
int LoopNr;
void setup() {
//BautRate: bps, 4bit SPI SD-Card Reader Interface
Serial.begin(115200);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
Serial.print("Initializing SD card...");
if (!SD.begin(chipSelect)) {
Serial.println("initialization failed!");
return;
}
Serial.println("initialization done.");
//check the file
myFile = SD.open(CurrentFilename.c_str());
if (myFile)
{
Serial.println(CurrentFilename);
}
else
{
// if the file didn't open, print an error:
Serial.println("error opening file");
return;
}
leds.begin();
leds.show();
}
void loop() {
ElapsedTimeInMS = 0;
for (int i = 0; i < NumberOfLEDs; i++)
{
int CurrentColor [3];
CalculateColors(myFile.parseFloat(), CurrentColor);
leds.setPixel(i, CurrentColor[0], CurrentColor[1], CurrentColor[2]);
}
Serial.println(ElapsedTimeInMS);
while (ElapsedTimeInMS < FrameTime) {} //wait until 40ms passed
leds.show();
ElapsedTimeInMS -= FrameTime;
Serial.println(LoopNr);
Serial.flush();
LoopNr++;
if (LoopNr == TotalNumberOfFrames)
{
//reset the file
LoopNr = 0;
myFile.close();
Serial.println("finished");
myFile = SD.open(CurrentFilename.c_str());
}
}
//Convert values to color values for red, green, blue from 0 to 255
void CalculateColors (float InputValue, int ColorArrayInput[])
{
float BaseValue;
if (InputValue > MaximumVorticityToShow) {
BaseValue = 255;
}
else
{
BaseValue = InputValue / MaximumVorticityToShow * 255;
}
ColorArrayInput[0] = 255; //(int)(BaseValue + .5); //Red
ColorArrayInput[1] = -0.39 * BaseValue + 100; //Green
ColorArrayInput[2] = 0; //(int)(-1 * BaseValue + 255.5); //Blue
}
Nach etwa 8000 loop Durchläufen. Da liest er gerade die 1600 Spalten aus Zeile 8000 der CSV. Ich lasse jeden Loop die Zahl der Durchläufe und die benötigte Rechenzeit ausgeben. Dazu verwende ich die teensy eigene Funktion: Delay and Timing Functions
Scheinbar hat es mit der SD.h library oder meiner Art des Zugriffs darauf zutun. Wenn ich die "SdFs.h" (GitHub - greiman/SdFs: Arduino FAT16/FAT32/exFAT Library) Library verwende, sinkt zum einen die Rechenzeit für einen loop von knapp 30ms auf 12ms und außerdem gibt es kein Stocken mehr.