This is my first arduino project and first time programing anything, it's been really fun! The hardware here is nothing new but I've not seen much with vvvv or computer -> arduino using serial.
I decided to make one of those 333 led cubes as a learning project then control it over serial using vvvv to turn it into a simple 3 channel spectrum analyser. Bass Mid and High are displayed on one face of the cube then cascade away from the viewer. I made my own multiplexing code.
Information is extracted from the audio using FFT module in vvvv, some simple processing done then sent over serial to arduino as 3 bytes, bass mid and treble. Each byte can have the values 0, 1, 2, 3. I had lots of problems with bytes end up in the wrong part of the array that contains the data. I tried to fix this by having vvvv send only one byte of data at a time and getting the arduino to send a byte down to vvvv to let it know when it's ready for the next one. VVVV however did not like having data from the RS232 modules output being put anywhere back into the stream going into its input even if it was just toggling a switch. Strange.
I found that having "if (Serial.available() >= 3)" was necessary for the data to be inputted properly and also 'Send Data' on the RS232 module in vvvv musn't be set to 1 constantly it must be triggered by an LFO.
Hope this helps someone... I found this forum very useful. Criticism appreciated.
int col[] = { 5, 6, 7, 8, 9, 10, 11, 12, 13 }; // an array of pin numbers to which LED columns are attached
int lev[] = { 2, 3, 4 }; //pins for each level declared
int time = 5; //refresh rate total delay is 3*this so 15ms
int x = 0; //serial get loop
int itter = 5;
//array1 is the 'front' layer which takes the values from the serial port
//array2 is the second layer which takes values from array1
//array3 is the third layer which takes values from array2 and are then discarded
char array2[3] = { '0', '0', '0' };
char array3[3] = { '0', '0', '0' };
char array1[3] = { '0', '0', '0' };
void setup() {
//turn on serial
Serial.begin(9600);
int thisPin;
// pins are activated as outputs
for (int thisPin = 0; thisPin < 9; thisPin++) {
pinMode(col[thisPin], OUTPUT);
}
for (int thisPin = 0; thisPin < 3; thisPin++) {
pinMode(lev[thisPin], OUTPUT);
}
}
void loop() {
//if enough serial data is available the data is loaded into array1.
//data is an array of 3 strings 000 010 021 etc from vvvv
//the numbers show how many leds are turned on in each column of the front layer, bottom up
if (Serial.available() >= 3) {
for ( int i = 0; i < 3; i++)
array1[i]= Serial.read() ;
}
x = x+1; //Here variable x is increased by 1 each itteration of the program
if (x == itter){ //Can vary how often the arrays cascade down here
int i = 0;
while (i<3){
array3[i]=array2[i];
array2[i]=array1[i];
i++;
}
x = 0;
}
//Bottom level is activated
digitalWrite(lev[0],HIGH);
digitalWrite(lev[1],LOW );
digitalWrite(lev[2],LOW);
//the arrays are iterated though checking weather the leds on the bottom level need to be turned on or not
int i = 0;
while (i < 3) {
if (array1[i] != '0'){
digitalWrite(col[i], HIGH);
}
if (array1[i] == '0'){
digitalWrite(col[i], LOW);
}
if (array2[i] != '0'){
digitalWrite(col[i+3], HIGH);
}
if (array2[i] == '0'){
digitalWrite(col[i+3], LOW);
}
if (array3[i] != '0'){
digitalWrite(col[i+6], HIGH);
}
if (array3[i] == '0'){
digitalWrite(col[i+6], LOW);
}
i++;
}
delay(time);
//Middle level is activated and the arrays iterated through.
digitalWrite(lev[0],LOW);
digitalWrite(lev[1],HIGH );
digitalWrite(lev[2],LOW);
i = 0;
while (i < 3) {
if (array1[i] == '2'){
digitalWrite(col[i], HIGH);
}
if (array1[i] == '3'){
digitalWrite(col[i], HIGH);
}
if (array1[i] == '0'){
digitalWrite(col[i], LOW);
}
if (array1[i] == '1'){
digitalWrite(col[i], LOW);
}
if (array2[i] == '2'){
digitalWrite(col[i+3], HIGH);
}
if (array2[i] == '3'){
digitalWrite(col[i+3], HIGH);
}
if (array2[i] == '0'){
digitalWrite(col[i+3], LOW);
}
if (array2[i] == '1'){
digitalWrite(col[i+3], LOW);
}
if (array3[i] == '2'){
digitalWrite(col[i+6], HIGH);
}
if (array3[i] == '3'){
digitalWrite(col[i+6], HIGH);
}
if (array3[i] == '0'){
digitalWrite(col[i+6], LOW);
}
if (array3[i] == '1'){
digitalWrite(col[i+6], LOW);
}
i++;
}
delay(time);
//top layer is activated. you know the drill here
digitalWrite(lev[0],LOW);
digitalWrite(lev[1],LOW );
digitalWrite(lev[2],HIGH);
i = 0;
while (i < 3) {
if (array1[i] == '3'){
digitalWrite(col[i], HIGH);
}
if (array1[i] != '3'){
digitalWrite(col[i], LOW);
}
if (array2[i] == '3'){
digitalWrite(col[i+3], HIGH);
}
if (array2[i] != '3'){
digitalWrite(col[i+3], LOW);
}
if (array3[i] == '3'){
digitalWrite(col[i+6], HIGH);
}
if (array3[i] != '3'){
digitalWrite(col[i+6], LOW);
}
i++;
}
delay(time);
//Fin!
}
VVVV patch: