The LED flashing circuit makes use of the Minim audio library and the Arduino program Processing to analyze sound, producing a response based on a snare drum hit, a bass drum hit, and a hi-hat hit from the percussion of the audio file.
Remove these ads by
Signing UpStep 1Parts/Tools Needed
Hardware:
1. An Arduino microcontroller board. There are many versions of the Arduino, but I would recommend the Arduino Duemilanove. You can buy one online for around $20.
2. Three LEDs (different colors preferred, so you can see the difference in beats easier - I used a red, yellow, and green LED)
3. Three resistors (depending on your LEDs, the resistor value will be different - check the ratings on the LEDs to see what resistance corresponds to their maximum brightness, without burning them out)
4. A solderless breadboard
5. Some wire, to use as leads from the Arduino to the LEDs/resistors on the breadboard
6. A computer
7. A USB cable (A to B)
Software:
1. Arduino Software Environment
2. Processing Software Environment
3. The "arduino" library for Processing
4. The BeatWrite / BeatListener code from the minim JavaSound library examples
Download links for the software will follow in Step 3.
| « Previous Step | Download PDFView All Steps | Next Step » |









































~Hyrulian
In processing, in line 35,
arduino = new Arduino(this, Arduino.list()[1], 57600);
I get an error saying, ArrayIndexOutOfBoundsException: 1
What do I do? I've had my Arduino Duemilaneve for about 4 days now, so I'm really a noob, Haha :p
Please help,
much appreciated.
try that
Take a look at the post I made to Sentinel in the comments below. I have quoted it here for your convenience:
It looks like you have other serial devices connected to your computer, other than the Arduino. Try calling Arduino.list() on its own line in the setup() portion of the program, like this:
void setup() {
println(Arduino.list());
}
Then choose the appropriate Arduino listing when you make a new Arduino object, like this:
arduino = new Arduino(this, Arduino.list()[Whatever index you find in the Arduino.listI()], 57600);
~Hyrulian
/**
* This sketch demonstrates how to use the BeatDetect object in FREQ_ENERGY mode.
* You can use
isKick,isSnare, isHat,isRange,* and
isOnset(int)to track whatever kind of beats you are looking to track, they will report* true or false based on the state of the analysis. To "tick" the analysis you must call
detect* with successive buffers of audio. You can do this inside of
draw, but you are likely to miss some* audio buffers if you do this. The sketch implements an
AudioListenercalledBeatListener* so that it can call
detecton every buffer of audio processed by the system without repeating a buffer* or missing one.
*
* This sketch plays an entire song so it may be a little slow to load.
*/
import processing.serial.*;
import ddf.minim.*;
import ddf.minim.analysis.*;
import cc.arduino.*;
Minim minim;
AudioPlayer song;
BeatDetect beat;
BeatListener bl;
Arduino arduino;
int ledPin = 12; // LED connected to digital pin 12
int ledPin2 = 8; // LED connected to digital pin 1
int ledPin3 = 2; // LED connected to digital pin 0
float kickSize, snareSize, hatSize;
void setup() {println.Arduino.list();}
size(512, 200, P3D);
minim = new Minim(this);
arduino = new Arduino(this, Arduino.list()[1], 57600);
song = minim.loadFile("Soy Bomb", 2048);
song.play();
// a beat detection object that is FREQ_ENERGY mode that
// expects buffers the length of song's buffer size
// and samples captured at songs's sample rate
beat = new BeatDetect(song.bufferSize(), song.sampleRate());
// set the sensitivity to 300 milliseconds
// After a beat has been detected, the algorithm will wait for 300 milliseconds
// before allowing another beat to be reported. You can use this to dampen the
// algorithm if it is giving too many false-positives. The default value is 10,
// which is essentially no damping. If you try to set the sensitivity to a negative value,
// an error will be reported and it will be set to 10 instead.
beat.setSensitivity(100);
kickSize = snareSize = hatSize = 16;
// make a new beat listener, so that we won't miss any buffers for the analysis
bl = new BeatListener(beat, song);
textFont(createFont("Helvetica", 16));
textAlign(CENTER);
arduino.pinMode(ledPin, Arduino.OUTPUT);
arduino.pinMode(ledPin2, Arduino.OUTPUT);
arduino.pinMode(ledPin3, Arduino.OUTPUT);
}
void draw() {
background(0);
fill(255);
if(beat.isKick()) {
arduino.digitalWrite(ledPin, Arduino.HIGH); // set the LED on
kickSize = 32;
}
if(beat.isSnare()) {
arduino.digitalWrite(ledPin2, Arduino.HIGH); // set the LED on
snareSize = 32;
}
if(beat.isHat()) {
arduino.digitalWrite(ledPin3, Arduino.HIGH); // set the LED on
hatSize = 32;
}
arduino.digitalWrite(ledPin, Arduino.LOW); // set the LED off
arduino.digitalWrite(ledPin2, Arduino.LOW); // set the LED off
arduino.digitalWrite(ledPin3, Arduino.LOW); // set the LED off
textSize(kickSize);
text("KICK", width/4, height/2);
textSize(snareSize);
text("SNARE", width/2, height/2);
textSize(hatSize);
text("HAT", 3*width/4, height/2);
kickSize = constrain(kickSize * 0.95, 16, 32);
snareSize = constrain(snareSize * 0.95, 16, 32);
hatSize = constrain(hatSize * 0.95, 16, 32);
}
void stop() {
// always close Minim audio classes when you are finished with them
song.close();
// always stop Minim before exiting
minim.stop();
// this closes the sketch
super.stop();
}
Ok, println fixed that error, but now I get an error with the next line, line 36
size(512, 200, P3D); gest a "It looks like you're mixing "active" and "static" modes." error.
What should I do about this 1?
Thanks again for all your help!
I hope I'm not to much much of a bother, haha :P
You're not a bother at all, here's your problem, on this line:
void setup() {println.Arduino.list();}
You forgot to take out the ending bracket here when you were debugging. Take out the last curly bracket on this line, and you should be good, like this:
void setup() {println.Arduino.list();
~Hyrulian
That kinda fixed it, but I get a different error this time
void setup() {println.Arduino.list(); says " Cannot find anything named "println" "
Grrrr! This is getting a bit flustering ):
-ringofrizz
println.Arduino.list();
you should have
println(Arduino.list());
with the parentheses.
~Hyrulian
But then I get a "ArrayIndexOutOfBoundsException: 1" error on
arduino = new Arduino(this, Arduino.list()[1], 57600); still.
I don't get whats wrong :(
/**
* This sketch demonstrates how to use the BeatDetect object in FREQ_ENERGY mode.
* You can use
isKick,isSnare, isHat,isRange,* and
isOnset(int)to track whatever kind of beats you are looking to track, they will report* true or false based on the state of the analysis. To "tick" the analysis you must call
detect* with successive buffers of audio. You can do this inside of
draw, but you are likely to miss some* audio buffers if you do this. The sketch implements an
AudioListenercalledBeatListener* so that it can call
detecton every buffer of audio processed by the system without repeating a buffer* or missing one.
*
* This sketch plays an entire song so it may be a little slow to load.
*/
import processing.serial.*;
import ddf.minim.*;
import ddf.minim.analysis.*;
import cc.arduino.*;
Minim minim;
AudioPlayer song;
BeatDetect beat;
BeatListener bl;
Arduino arduino;
int ledPin = 12; // LED connected to digital pin 12
int ledPin2 = 8; // LED connected to digital pin 1
int ledPin3 = 2; // LED connected to digital pin 0
float kickSize, snareSize, hatSize;
void setup() {println(Arduino.list());
size(512, 200, P3D);
minim = new Minim(this);
arduino = new Arduino(this, Arduino.list()[1], 57600);
song = minim.loadFile("Soy Bomb", 2048);
song.play();
// a beat detection object that is FREQ_ENERGY mode that
// expects buffers the length of song's buffer size
// and samples captured at songs's sample rate
beat = new BeatDetect(song.bufferSize(), song.sampleRate());
// set the sensitivity to 300 milliseconds
// After a beat has been detected, the algorithm will wait for 300 milliseconds
// before allowing another beat to be reported. You can use this to dampen the
// algorithm if it is giving too many false-positives. The default value is 10,
// which is essentially no damping. If you try to set the sensitivity to a negative value,
// an error will be reported and it will be set to 10 instead.
beat.setSensitivity(100);
kickSize = snareSize = hatSize = 16;
// make a new beat listener, so that we won't miss any buffers for the analysis
bl = new BeatListener(beat, song);
textFont(createFont("Helvetica", 16));
textAlign(CENTER);
arduino.pinMode(ledPin, Arduino.OUTPUT);
arduino.pinMode(ledPin2, Arduino.OUTPUT);
arduino.pinMode(ledPin3, Arduino.OUTPUT);
}
void draw() {
background(0);
fill(255);
if(beat.isKick()) {
arduino.digitalWrite(ledPin, Arduino.HIGH); // set the LED on
kickSize = 32;
}
if(beat.isSnare()) {
arduino.digitalWrite(ledPin2, Arduino.HIGH); // set the LED on
snareSize = 32;
}
if(beat.isHat()) {
arduino.digitalWrite(ledPin3, Arduino.HIGH); // set the LED on
hatSize = 32;
}
arduino.digitalWrite(ledPin, Arduino.LOW); // set the LED off
arduino.digitalWrite(ledPin2, Arduino.LOW); // set the LED off
arduino.digitalWrite(ledPin3, Arduino.LOW); // set the LED off
textSize(kickSize);
text("KICK", width/4, height/2);
textSize(snareSize);
text("SNARE", width/2, height/2);
textSize(hatSize);
text("HAT", 3*width/4, height/2);
kickSize = constrain(kickSize * 0.95, 16, 32);
snareSize = constrain(snareSize * 0.95, 16, 32);
hatSize = constrain(hatSize * 0.95, 16, 32);
}
void stop() {
// always close Minim audio classes when you are finished with them
song.close();
// always stop Minim before exiting
minim.stop();
// this closes the sketch
super.stop();
}
-ringofrizz (:
/**
* This sketch demonstrates how to use the BeatDetect object in FREQ_ENERGY mode.
* You can use isKick, isSnare, isHat, isRange,
* and isOnset(int) to track whatever kind of beats you are looking to track, they will report
* true or false based on the state of the analysis. To "tick" the analysis you must call detect
* with successive buffers of audio. You can do this inside of draw, but you are likely to miss some
* audio buffers if you do this. The sketch implements an AudioListener called BeatListener
* so that it can call detect on every buffer of audio processed by the system without repeating a buffer
* or missing one.
*
* This sketch plays an entire song so it may be a little slow to load.
*/
import processing.serial.*;
import ddf.minim.*;
import ddf.minim.analysis.*;
import cc.arduino.*;
Minim minim;
AudioPlayer song;
BeatDetect beat;
BeatListener bl;
Arduino arduino;
int ledPin = 12; // LED connected to digital pin 12
int ledPin2 = 8; // LED connected to digital pin 1
int ledPin3 = 2; // LED connected to digital pin 0
float kickSize, snareSize, hatSize;
void setup() {
println(Arduino.list());
}
void draw() {
background(0);
fill(255);
if(beat.isKick()) {
arduino.digitalWrite(ledPin, Arduino.HIGH); // set the LED on
kickSize = 32;
}
if(beat.isSnare()) {
arduino.digitalWrite(ledPin2, Arduino.HIGH); // set the LED on
snareSize = 32;
}
if(beat.isHat()) {
arduino.digitalWrite(ledPin3, Arduino.HIGH); // set the LED on
hatSize = 32;
}
arduino.digitalWrite(ledPin, Arduino.LOW); // set the LED off
arduino.digitalWrite(ledPin2, Arduino.LOW); // set the LED off
arduino.digitalWrite(ledPin3, Arduino.LOW); // set the LED off
textSize(kickSize);
text("KICK", width/4, height/2);
textSize(snareSize);
text("SNARE", width/2, height/2);
textSize(hatSize);
text("HAT", 3*width/4, height/2);
kickSize = constrain(kickSize * 0.95, 16, 32);
snareSize = constrain(snareSize * 0.95, 16, 32);
hatSize = constrain(hatSize * 0.95, 16, 32);
}
void stop() {
// always close Minim audio classes when you are finished with them
song.close();
// always stop Minim before exiting
minim.stop();
// this closes the sketch
super.stop();
}
Look at what it prints out in your Serial Monitor, then change the value of the number "1" to whatever value the Arduino is.
~Hyrulian
It seems everything works except I get
"Cannot find a class or type named "BeatListener" " on BeatListener bl; :(
-ringofrizz
~Hyrulian
-ringofrizz
~Hyrulian
-ringofrizz
WARNING: RXTX Version mismatch
Jar version = RXTX-2.2pre1
native lib Version = RXTX-2.2pre2
Exception in thread "Animation Thread" java.lang.ArrayIndexOutOfBoundsException: 1
at BeatWrite.setup(BeatWrite.java:59)
at processing.core.PApplet.handleDraw(Unknown Source)
at processing.core.PApplet.run(Unknown Source)
at java.lang.Thread.run(Thread.java:662)
It also highlights
arduino = new Arduino(this, Arduino.list()[1], 57600);
Within the script. Any ideas/help? It would be much appreciated.
and it worked.
I dont know about RXTX mismatch error
1) does this project only work with PC?
2) where is Processing's library?
3) could you make another picture of how to put the Arduino folder into Processing's library?
4) is the Arduino in the picture a UNO?
5) can the latest Arduino UNO work for this project
Thanks guys, this is really all I ask for!!!
after this im still getting the error
the package "cc" does not exist. you might be missing a library.
no library found for cc.arduino
as of release 1.0, libraries most be installed in a folder named 'libraries' inside the 'sketchbook' folder.
i tried looking or the sketchbook folder but i cant find it, do i need to make it?
Here's the exact message:
Cannot find a class or type named "BeatListener"
the package "cc" does not exist. you might be missing a library.
no library found for cc.arduino
as of release 1.0, libraries most be installed in a folder named 'libraries' inside the 'sketchbook' folder.
can someone please help.
2)Download this -> Processing Library: processing-arduino.zip (Updated 11 Nov. 2011)
3) Unzip the file and you can find "arduino" folder
3) Copy "arduino" file into libraries(in processing folder)
4) and restart