Creating a Plasma effect for the Arduino and the Sparkfun LED tile

After having discovered the Arduino and before attacking the network extension I wanted to create something fun with the board and the 8 by 8 LED tile.

So I came with the idea of using one old school plasma effect of ArKaos VJ and porting it to the Arduino.

Here is the result:

Basically there are 2 textures pre-computed at startup. They are moved on a circular motion.

The 2 textures are moved and summed and you obtain an height value for each pixel. To get a nice effect you then go through a color table that is also pre-computed at startup.

To have a nice rotation effect you shift the color table at each generation of a new image.

At the end of the video you have another simple loop I did to test my setup.

Here is the plasma code for the Arduino:

//
// Plasma generation for the Arduino and a RGB Serial Backpack Matrix from SparkFun Electronics
// Marco Hinic, built on top of the code of Ryan Owens
//

//Define the SPI Pin Numbers
#define DATAOUT 11//MOSI
#define DATAIN 12//MISO
#define SPICLOCK 13//sck
#define SLAVESELECT 10//ss

void LED_Setup()
{
//SPI Bus setup
SPCR = (1< 64 bytes
// 16 by 16 -> 256 bytes
// color table 256 bytes
//

#define PLASMA_W 8
#define PLASMA_H 8

#define TABLE_W 16
#define TABLE_H 16

unsigned char gPlasma[PLASMA_W*PLASMA_H];
unsigned char gTable1[TABLE_W*TABLE_H];
unsigned char gTable2[TABLE_W*TABLE_H];
unsigned char gColorTable[256];
float gCircle1, gCircle2, gCircle3, gCircle4, gCircle5, gCircle6, gCircle7, gCircle8;
int gRoll;

void Plasma_CalcTable1 ()
{
for (int i=0; i< TABLE_H; i++) { for (int j=0; j< TABLE_W; j++) { int index = (i*TABLE_W)+j; gTable1[index] = (unsigned char) ((sqrt(16.0+(PLASMA_H-i)*(PLASMA_H-i)+(PLASMA_W-j)*(PLASMA_W-j))-4) *5 ); } } } void Plasma_CalcTable2 () { for (int i=0; i< TABLE_H; i++) { for (int j=0; j< TABLE_W; j++) { int index = (i*TABLE_W)+j; float temp = sqrt(16.0+(PLASMA_H-i)*(PLASMA_H-i)+(PLASMA_W-j)*(PLASMA_W-j))-4; gTable2[index] = (sin(temp/9.5)+1)*90; } } } void Plasma_SetColor (int index, unsigned char red, unsigned char green, unsigned char blue) { unsigned char new_color = (red & 0xE0) + ((green & 0xE0) >> 3) + ((blue & 0xC0) >> 6);
gColorTable [index] = new_color;
}

double gRed, gGreen, gBlue;

#define color(u,a) (cos((u)+(a))+1)*127

void BuildColorTable()
{
double u;
int i;
for (i=0; i<256; i++) { u=2*PI/256*i; Plasma_SetColor(i,color(u,gRed),color(u,gGreen),color(u,gBlue)); } gRed+=0.05; gGreen-=0.05; gBlue+=0.1; } void Plasma_Setup () { gCircle1 = 0; gCircle2 = 0; gCircle3 = 0; gCircle4 = 0; gCircle5 = 0; gCircle6 = 0; gCircle7 = 0; gCircle8 = 0; gRoll = 0; for (int i=0; i

Leave a Reply

Your email address will not be published. Required fields are marked *