Hi Paul,
Still have an issue with my setup. Perhaps I am not using the library as intended.
I have modified the videodisplay.ino for this test case. Code included below.
The test case uses a local memory (not shared with library) that is filled with
colors for LED string. The filling is alternate pixels are turned on. The color is random.
Then the local memory is used with leds.setpixel() to display LEDs leds.show() which works just fine.
Then the local memory is copied into drawingMemory, using memcpy, then leds.show() generates "flashes" or incorrect LEDs color or intensity ( too bright)
Then once again the localmemory is copied into drawingMemory in a for loop, then leds.show() which again generates incorrects LEDs color or intensity.
I have attempted to include a [video]https://www.dropbox.com/lightbox/home/videos[/video][/URL] showing the effect of my code running on Teensy3.1.
Also Included is a test file showing debug output of local memory and drawing memory.
At one point I thought that I need to toggle pin12 for the DMAs to start, so I included appropriate code
within a #ifdef. But pin12 does not seem to matter.
Please let me know, if I am using the library as intended, if not what to fix?
Thank you
==============VideoDisplayWLocalmem.ino
/* OctoWS2811 VideoDisplay.ino - Video on LEDs, from a PC, Mac, Raspberry Pi
http://www.pjrc.com/teensy/td_libs_OctoWS2811.html
Copyright (c) 2013 Paul Stoffregen, PJRC.COM, LLC
Permission is hereby granted, ....edited for brevity
*/
#include <OctoWS2811.h>
#define LED_WIDTH 256 // number of LEDs horizontally hk: fake panel for 1 pin
#define LED_HEIGHT 8 // number of LEDs vertically (must be multiple of 8)
#define LED_LAYOUT 0 // 0 = even rows left->right, 1 = even rows right->left
#define VIDEO_XOFFSET 0
#define VIDEO_YOFFSET 0 // display entire image
#define VIDEO_WIDTH 100
#define VIDEO_HEIGHT 100
//#define VIDEO_XOFFSET 0
//#define VIDEO_YOFFSET 0 // display upper half
//#define VIDEO_WIDTH 100
//#define VIDEO_HEIGHT 50
//#define VIDEO_XOFFSET 0
//#define VIDEO_YOFFSET 50 // display lower half
//#define VIDEO_WIDTH 100
//#define VIDEO_HEIGHT 50
const int ledsPerStrip = LED_WIDTH * LED_HEIGHT / 8;
DMAMEM int displayMemory[ledsPerStrip*6];
int drawingMemory[ledsPerStrip*6];
int localmem[ledsPerStrip*6];
float gma = 1.7;
int gammatable[256];
elapsedMicros elapsedUsecSinceLastFrameSync = 0;
const int config = WS2811_GRB | WS2811_800kHz; // color config included for this test
OctoWS2811 leds(ledsPerStrip, displayMemory, drawingMemory, config);
void setup() {
pinMode(13, OUTPUT);
pinMode(12, OUTPUT);
Serial.begin(9600);
Serial.setTimeout(50);
for (int i=0; i < 256; i++) { // from movie2serial
gammatable
= (int)(pow((float)i / 255.0, gma) * 255.0 + 0.5);
}
leds.begin();
leds.show();
}
// fill local memory with one random color for all LEDs,
// Set alternating LEDs in strip with random color.
void fillmem() {
int index; int ledindex=0; int randclr;
unsigned char red,green,blue;
//blank out localmem and drawingMemory
for (index=0; index<ledsPerStrip*6;index++) {
localmem[index] = 0; drawingMemory[index] = 0;
}
// get a random color in the low power range
red=gammatable[random(8,16)];
green=gammatable[random(8,16)];
blue=gammatable[random(8,16)];
randclr=(red<<16)|(green<<8)|(blue);
for(ledindex=0;ledindex<ledsPerStrip*6;ledindex+=2) {
localmem[ledindex] = randclr; // every alternate LED is ON with randclr
drawingMemory[ledindex]=randclr; // If I use this in leds.setpixel it does not work
}
}
// LEDsOn turns on the whole string by three ways:
// 1. by using leds.setpixel() call, followed by leds.show
// 2. by using memcpy , to compy localmem to drawingMemory followed by leds.show
// 3. by using a for loop to copy each localmem pixel value to drawingMemory then leds.show
// Do not know if pin 12 actually turn on DMA internal to Teensy3.1
// so I included the code to generate sync any way. However
// it did not seem to make any difference if I included timing or not.
// To include timing, uncomment the next lines define.
// #define INC_TIME_DELAY_AND_PIN12 1
void LEDsON()
{ int k=0; int i; int j;
unsigned int startAt = micros();
unsigned int usecUntilFrameSync = 0;
fillmem(); // Get pattern of led turned ON all to one random color.
for(i=0;i<ledsPerStrip;i++) {
leds.setPixel(i, localmem); // using drawingMemory here does not work
}
Serial.println("Will display localmem via setpixel:");
printlocalmem();
leds.show();
delay(5000); // now wait a few secs and re do with memcpy
fillmem();
Serial.println("Will print drawingMemory after memcpy:");
memcpy(drawingMemory,localmem,ledsPerStrip*6); // after first numleds, rest of *6 is zero
printdrawingmem();
#ifdef INC_TIME_DELAY_AND_PIN12
unsigned int endAt = micros();
unsigned int usToWaitBeforeSyncOutput = 100;
if (endAt - startAt < usecUntilFrameSync) {
usToWaitBeforeSyncOutput = usecUntilFrameSync - (endAt - startAt);
}
digitalWrite(12, HIGH);
delayMicroseconds(usToWaitBeforeSyncOutput);
digitalWrite(12, LOW);
#endif
// WS2811 update begins immediately after falling edge of frame sync
leds.show();
delay(5000);
fillmem();
for(i=0;i<ledsPerStrip*6;i++) {
drawingMemory=localmem;
}// i
Serial.println("Will print drawingMemory after for loop copy:");
printdrawingmem();
#ifdef INC_TIME_DELAY_AND_PIN12
endAt = micros();
usToWaitBeforeSyncOutput = 100;
if (endAt - startAt < usecUntilFrameSync) {
usToWaitBeforeSyncOutput = usecUntilFrameSync - (endAt - startAt);
}
digitalWrite(12, HIGH);
delayMicroseconds(usToWaitBeforeSyncOutput);
digitalWrite(12, LOW);
// WS2811 update begins immediately after falling edge of frame sync
#endif
leds.show();
delay(5000);
}
// Following routines for displaying contents of local/drawing memories
// on a serial PuTTy terminal connected to Teensy3.1
// The color to ascii routine returns one character:
// if pixel has value return "*" else return "."
char clrtoascii(int v)
{
char c;
if(v>0) {c = '*';} else {c='.';}
return c;
}
// Print drawingMemory contents
void printdrawingmem() // print a 48 x 32 array of chars
{
int x,y;
for (y=0;y<32;y++) {
for(x=0;x<48;x++) {
Serial.write(clrtoascii(drawingMemory[x+(48*y)]));
}
Serial.println();
}
Serial.println();
}
// Print localmemory contents
void printlocalmem() // print a 48 x 32 array of chars
{
int x,y;
for (y=0;y<32;y++) {
for(x=0;x<48;x++) {
Serial.write(clrtoascii(localmem[x+(48*y)]));
}
Serial.println();
}
Serial.println();
}
void loop() {
digitalWrite(13, HIGH);
LEDsON();
digitalWrite(13, LOW);
delay(2000);
}
============== Debug print text out
Will display localmem via setpixel:
*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.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