FastCat asks,
But here you can give a simple code. As with Rainbowduino on 8x8 rgb matrix to light only one LED (for example the extreme lower left) alternately - red, green and blue colors ?
I wanted to do the same thing, you'd think that setting pixel at x,y to color r,g,b, would be included in the basic firmware, but it's not. After looking over the code and some examples of what other people have been doing with firmware modifications, I ended up modifying Rainbow_CMD_V2_0.pde (supplied by Seeedstudio) and added a new command: SetPixelXY, which sets a particular pixel to a particular color. The code for the new command, which I added to Rainbow_CMD_V2_0.pde, looks like:
//==================================
// setPixelXY extends command set
// function: sets a specific pixel to a specific color
// x,y coordinates packed into the fifth byte of CMD stream
void setPixelXY(void) {
unsigned char x; unsigned char y;
unsigned char r; unsigned char g; unsigned char b;
r=(RainbowCMD[2]&0x0F);
g=((RainbowCMD[3]>>4)&0x0F);
b=(RainbowCMD[3]&0x0F);
x=((RainbowCMD[4]>>4)&0x0F);
y=(RainbowCMD[4]&0x0F);
RainbowCMD[1]=0;
x &= 7;
y &= 7;
if ((x & 1) == 0) {
dots_color[Buffprt][0][y][x >> 1] = r |
(dots_color[Buffprt][0][y][x >> 1] & 0xF0);
dots_color[Buffprt][1][y][x >> 1] = g |
(dots_color[Buffprt][1][y][x >> 1] & 0xF0);
dots_color[Buffprt][2][y][x >> 1] = b |
(dots_color[Buffprt][2][y][x >> 1] & 0xF0);
} else {
dots_color[Buffprt][0][y][x >> 1] = (r << 4) |
(dots_color[Buffprt][0][y][x >> 1] & 0x0F);
dots_color[Buffprt][1][y][x >> 1] = (g << 4) |
(dots_color[Buffprt][1][y][x >> 1] & 0x0F);
dots_color[Buffprt][2][y][x >> 1] = (b << 4) |
(dots_color[Buffprt][2][y][x >> 1] & 0x0F);
}
}
For this to work you need to also change to the event handler (add this to the switch statement handling incoming commands):
// Extend the Rainbowduino firmware to support new command
case setPixels:
setPixelXY();
break;
And you also need to a new define in Rainbow.h for the new command:
#define setPixels 0x04 // extend command set to support SetPixelXY
So now the firmware responds to a the new SetPixelXY command. To be able to send this command from an Arduino to the Rainbowduino via I2C, I modified SeeedMaster.pde (provided by Seeedstudio) to include an interface which sends the new command to the Rainbowduino:
//================================
// Name: SetPixelXY
// function: Send conmand to Rainbowduino to
// set a pixel to a particular color
// parameter: Address: Rainbowduino I2C address
// red, green, blue: the color RGB
// x,y: the coordinates of the pixel
// Extension to Rainbowduino command set by David Tames
// inspired by some code from MeggyJr_Plasma.pde 0.3
// Google Code Archive - Long-term storage for Google Code Project Hosting.
// Released under terms of GNU General Public License
//
void SetPixelXY(int Adr, unsigned char X, unsigned char Y, unsigned char R, unsigned char G, unsigned char B) {
unsigned char p;
// change coordinates so that 0,0 is in lower left and 7,7 is in upper right.
unsigned char TranslateX[8]={6,7,4,5,2,3,0,1};
// unsigned char TranslateY[8]={7,6,5,4,3,2,1,0}; // use if you want 0,0 in upper left
p = R; R = G; G = p; p = 0; // why do we need this kludge?
X = TranslateX[X]; // have coordinates go 0,1,2,3 etc. instead of 1,0,3,2, etc.
// Y = TranslateX[Y]; // use if you want 0,0 in top left instead of bottom left
RainbowCMD[0]='R';
RainbowCMD[1]=0x04; // extension to command set, requires revised firmware!
RainbowCMD[2]=R;
RainbowCMD[3]=((G<<4)|(B));
RainbowCMD[4]=((X<<4)|(Y)); // Pack X into high nybble, Y into low nybble
SentCMD(Adr);
}
Here's an example that draws a blue field and then a red "X" (I placed this at the top of SeeedMaster.pde :
void setup() {
Wire.begin(); // join i2c bus (address optional for master)
// start off with dim blue background
// color range 0-15 for each of R, G, B
ShowColor(4, 0, 0, 1);
}
void loop() {
unsigned char x;
unsigned char y;
int test;
// Draw a red x on blue background in order to demo use of SetPixelXY
for(x=0;x<8;x++) {
SetPixelXY(4, x, x, 1, 0, 0);
delay(50);
}
y = 7;
for(x=0;x<8;x++) {
SetPixelXY(4, x, y--, 1, 0, 0);
delay(50);
}
delay(1000);
for(x=0;x<8;x++) {
SetPixelXY(4, x, x, 0, 0, 1);
delay(50);
}
y = 7;
for(x=0;x<8;x++) {
SetPixelXY(4, x, y--, 0, 0, 1);
delay(50);
}
}
Now this is my first attempt programming in Arduino-land and my first encounter with the Rainbowduino, so it's a little messy and I have what I'm sure is a silly question for those more experienced with the Rainbowduino: Why did I have I need the kludge that switches around the color values for proper color display? I got it to work, but there's something funky going on with the nybbles representing red, green, and blue. Further elaboration on the ins and outs of the Rainbowduino is something I'd be interested in seeing from someone who's worked with the Rainbowduino much more than I have.