progress:RGB data to LPD8806

based on code by pbhurges
found here:

http://forums.adafruit.com/viewtopic.php?f=47&t=24731#p128613

Processing:

import processing.video.*;
import processing.serial.*;

//Video Stuff
Capture video;
int pixelCols = 1;
int pixelRows = 1;
int pixelWidth;
int pixelHeight;

float r;
float g;
float b;

static final int
nLEDs = 8,
latchLen = (nLEDs + 63) / 64;
color[] led = new color[nLEDs];
byte[] serialBuf = new byte[3 * (nLEDs + latchLen)],
gamma = new byte[256];
Serial port;

void setup(){
video = new Capture(this,640,480,30);

size(640,480);
pixelWidth = 640 / pixelCols;
pixelHeight = 480 / pixelRows;
// The “gamma”table actually does three things:applies gamma
// correction to input colors to produce a more perceptually linear
// output range,reduces 8-bit inputs to 7-bit outputs,and sets the
// high bit as required by the LPD8806 LED data protocol.
for(int i=0;i<256;i++){
gamma[i] = (byte)(0x80 | (int)(pow(((float)i / 255.0),2.5) * 127.0 + 0.5));
}

// Assumes Arduino is first/only serial device. Change to suit:
port = new Serial(this,Serial.list()[1],115200);
// colorMode(HSB,10);// Easy rainbows
//colorMode(HSB,10);

}

void draw(){
/////////////video stuff//////////////////

//
if(video.available())
{
video.read();
video.loadPixels();
}

for(int x = 0;x < 640;x += pixelWidth)
{
for(int y = 0;y < 480;y += pixelHeight)
{
int index = x + y * 640;
r = red(video.pixels[index]);
g = green(video.pixels[index]);
b = blue(video.pixels[index]);

// send the 9 color values like this in serial

noStroke();
fill(r,g,b);
rect(x,y,pixelWidth,pixelHeight);
//output = r + "," + g+ ","+ b + "\n";
//port.write(output);
//delay(100);
}
}

//////////////////////////////
//
int i,j;
//
//
//
// // Fill the led color array with something interesting:
for(i=0;i led[i] = color((frameCount + i) % r,g,b);
}
// // Convert data from led color array to LPD8806-ready format:
for(i=j=0;i serialBuf[j++] = gamma[(led[i] >> 8) &0xff];
serialBuf[j++] = gamma[(led[i] >> 16) &0xff];
serialBuf[j++] = gamma[ led[i] &0xff];
}
// // Arrays are zero-initialized in Processing/Java,
// // so no need to set up the latch data;it’s already there.
port.write(serialBuf);// Issue LPD8806 data to Arduino

// You *might* need to comment out the above line and use
// the following code instead. Long writes fail for some
// unknown reason. RXTX lib? Processing? Java? OS? Hardware?
// for(i=0;i// j = i + 255;
// if(j > serialBuf.length) j = serialBuf.length;
// port.write(Arrays.copyOfRange(serialBuf,i,j));
// }
}

// LPD8806 streamer:redirects bytes from serial in to SPI out.
// No processing is performed on the data,strictly forwarding.

#include

void setup(){
int c;
Serial.begin(115200);// 32u4 ignores BPS,runs full speed
// SPI is run at 2 MHz. LPD8806 can run much faster,
// but unshielded wiring is susceptible to interference.
// Feel free to experiment with other divider ratios.
SPI.begin();
SPI.setClockDivider(SPI_CLOCK_DIV8);
SPDR = 0;// Dummy byte out to “prime”the SPI status register

for(;;){// loop() is avoided for max throughput
while((c = Serial.read()) < 0);// Wait for next serial byte in
while(!(SPSR &(1< SPDR = c;// Issue new SPI byte out
}
}

void loop(){} // Do nothing

Leave a Reply

  

  

  

You can use these HTML tags

<a href=""title=""><abbr title=""><acronym title=""><b><blockquote cite=""><cite><code><del datetime=""><em><i><q cite=""><strike><strong>