We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
Page Index Toggle Pages: 1
sonia to arduino (Read 578 times)
sonia to arduino
May 13th, 2007, 10:22pm
 
Hello.

I am trying to figure out a way to use a microphone input from sonia to make my led lights blinking based on the fft number from the sound input.

Below is the coding that I am working on. When I run this program, leds will blink through my Arduino setup but they blink only once and stop. Also, there is no visual that will show up in processing and it doesn't even give me any error message...

Could anyone please help me?

Thank you!


//////////////////////////////////////

import processing.serial.*;

import pitaru.sonia_v2_9.*;
import SoniaHelper.*;


int spectrumLength=256; // Needs to be power of 2
int bandsteps;
float maxdist,damperval;
SoniaHelper ffthelper;
float pt[];

Serial myPort; //the serial port


void setup () {
 size(700,250);
 Sonia.start(this);
 frameRate(50);
 LiveInput.start(spectrumLength);
//  LiveInput.useEnvelope(true,1f);
 LiveInput.useEqualizer(true);  

 // SoniaHelper(int _n, int _nbands,boolean doAvg)
 ffthelper=new SoniaHelper(spectrumLength,32,false);
 ffthelper.setMaxLimits(200,2000);
 damperval=0.1f;
 ffthelper.setDamper(damperval);  
 
 pt=new float[spectrumLength*2];
 for(int i=0; i<spectrumLength; i++) {
   pt[i*2]=random(width-50)+25;
   pt[i*2+1]=random(height-50)+25;
 }
 bandsteps=spectrumLength/ffthelper.band.length;

 // Get the maximum distance the max value will travel.
 // Note that the max, maxMaximum and maxMinimum fields are
 // doubles. We need to cast them to float to use them here.
 maxdist=ffthelper.maxMaximum-ffthelper.maxMinimum;
}

void draw() {
 float rad;

 background(0);
 noStroke();
 
 doSoundInput();
 
 println(Serial.list());
 myPort = new Serial(this, Serial.list()[0], 9600);
 myPort.write(spectrumLength/ffthelper.band.length);

 for(int i=0; i<spectrumLength; i++) {
    fill(255,0,128, 255*ffthelper.spectrum[i]);
   
    // scale rad according to spectrum value, using
    // cubic interpolation to give organic values.
    rad=2+50*(ffthelper.spectrum[i]*ffthelper.spectrum[i]);
   
    ellipse(pt[i*2],pt[i*2+1], rad,rad);
 }
 
 // show damper value
 fill(0,100,200);
 rect(660,0, 30,1);
 rect(660,0+height*damperval, 30,1);
 rect(660,height-1, 30,1);
}

void mouseDragged() {
mousePressed();
}

void mousePressed() {
   damperval=(float)mouseY/(float)height;
   if(damperval>1) damperval=1;
   else if(damperval<0) damperval=0;
   ffthelper.setDamper(damperval);  
   println("damperval "+damperval);
}

public void doSoundInput() {
 LiveInput.getSpectrum();
 ffthelper.update(LiveInput.spectrum);
}
Page Index Toggle Pages: 1