How to Make LEDs Flash to Music with an Arduino

 by Hyrulian
This is a guide to make an LED flashing circuit that "beats" to an mp3 file on your computer, which can add an awesome effect to any sound-related device, or even your room (if you extend the concept with LED drivers or plenty of resistors/transistors).

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 adsRemove these ads by Signing Up

Step 1: Parts/Tools Needed

CIMG0121.JPG
Here is what you'll need to make the LED beat flashing circuit:

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.

1-40 of 98Next »
BobThAK says: May 8, 2013. 6:16 PM
I'm getting this. lol

Exception in thread "AWT-EventQueue-0" java.lang.RuntimeException: No framebuffer objects available
at processing.opengl.PGL$PGLListener.init(PGL.java:3255)
at jogamp.opengl.GLDrawableHelper.init(GLDrawableHelper.java:532)
at jogamp.opengl.GLDrawableHelper.init(GLDrawableHelper.java:552)
at javax.media.opengl.awt.GLCanvas$5.run(GLCanvas.java:1032)
at jogamp.opengl.GLDrawableHelper.invokeGLImpl(GLDrawableHelper.java:1019)
at jogamp.opengl.GLDrawableHelper.invokeGL(GLDrawableHelper.java:896)
at javax.media.opengl.awt.GLCanvas$7.run(GLCanvas.java:1060)
at javax.media.opengl.Threading.invoke(Threading.java:193)
at javax.media.opengl.awt.GLCanvas.display(GLCanvas.java:461)
at javax.media.opengl.awt.GLCanvas.paint(GLCanvas.java:516)
at sun.awt.RepaintArea.paintComponent(RepaintArea.java:248)
at sun.awt.RepaintArea.paint(RepaintArea.java:224)
at sun.awt.windows.WComponentPeer.handleEvent(WComponentPeer.java:308)
at java.awt.Component.dispatchEventImpl(Component.java:4736)
at java.awt.Component.dispatchEvent(Component.java:4488)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:668)
at java.awt.EventQueue.access$400(EventQueue.java:81)
at java.awt.EventQueue$2.run(EventQueue.java:627)
at java.awt.EventQueue$2.run(EventQueue.java:625)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:98)
at java.awt.EventQueue$3.run(EventQueue.java:641)
at java.awt.EventQueue$3.run(EventQueue.java:639)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:638)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
Exception in thread "Animation Thread" java.lang.RuntimeException: java.lang.RuntimeException: Processing cannot run because GLSL shaders are not available.
at jogamp.common.awt.AWTEDTExecutor.invoke(AWTEDTExecutor.java:58)
at jogamp.opengl.awt.AWTThreadingPlugin.invokeOnOpenGLThread(AWTThreadingPlugin.java:99)
at jogamp.opengl.ThreadingImpl.invokeOnOpenGLThread(ThreadingImpl.java:205)
at javax.media.opengl.Threading.invokeOnOpenGLThread(Threading.java:172)
at javax.media.opengl.Threading.invoke(Threading.java:191)
at javax.media.opengl.awt.GLCanvas.display(GLCanvas.java:461)
at processing.opengl.PGL.requestDraw(PGL.java:1195)
at processing.opengl.PGraphicsOpenGL.requestDraw(PGraphicsOpenGL.java:1550)
at processing.core.PApplet.run(PApplet.java:2140)
at java.lang.Thread.run(Thread.java:662)
Caused by: java.lang.RuntimeException: Processing cannot run because GLSL shaders are not available.
at processing.opengl.PGraphicsOpenGL.getGLParameters(PGraphicsOpenGL.java:6077)
at processing.opengl.PGraphicsOpenGL.beginDraw(PGraphicsOpenGL.java:1580)
at processing.core.PApplet.handleDraw(PApplet.java:2219)
at processing.opengl.PGL$PGLListener.display(PGL.java:3240)
at jogamp.opengl.GLDrawableHelper.displayImpl(GLDrawableHelper.java:573)
at jogamp.opengl.GLDrawableHelper.display(GLDrawableHelper.java:558)
at javax.media.opengl.awt.GLCanvas$6.run(GLCanvas.java:1049)
at jogamp.opengl.GLDrawableHelper.invokeGLImpl(GLDrawableHelper.java:1021)
at jogamp.opengl.GLDrawableHelper.invokeGL(GLDrawableHelper.java:896)
at javax.media.opengl.awt.GLCanvas$7.run(GLCanvas.java:1060)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:199)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:666)
at java.awt.EventQueue.access$400(EventQueue.java:81)
at java.awt.EventQueue$2.run(EventQueue.java:627)
at java.awt.EventQueue$2.run(EventQueue.java:625)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:636)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
The Expert Noob says: May 5, 2013. 7:13 PM
my best settings came as:

beat.setSensitivity(1);
kickSize = snareSize = hatSize = 500

time to rig it up to some bridge rectifiers, isolators and some A/C lights
Iraz says: May 1, 2013. 6:01 PM
It says serial does not run in 64-bit mode? Can anyone help me?
jordxn says: Apr 6, 2013. 2:49 PM
Also had the "the package "cc" does not exist issue. To fix -- In the Processing Editor, select "Sketch" > "Add File", then just select the "Ardunio.jar" file. Should work!

I also got "ArrayIndexOutOfBoundsException" -- To get this fixed;

Changed line 35 from;
arduino = new Arduino(this, Arduino.list()[1], 57600);
To;
arduino = new Arduino(this, Arduino.list()[0], 57600);

And then it works!! :)
rmoorjani says: Dec 17, 2012. 7:35 PM
Hey guys, I fixed the "the package "cc" does not exist. you might be missing a library." error! ITS SUPER SIMPLE! Just go to /libraries/arduino/library/ and rename the Arduino.jar to arduino.jar with a lowercase :)
skyfly200 in reply to rmoorjaniMar 15, 2013. 10:46 PM
I have this error and this did not help
Doctor_Donna says: Jan 27, 2013. 2:23 PM
Well now I fixed that... But now it's saying:

"NullPointerException" on processing
An highlighting the line "song = minim.loadfile("mysong.mp3", 2048);"
Doctor_Donna says: Jan 27, 2013. 12:52 PM
Well, I fixed the "Cannot find a class or type named 'BeatListener'" problem... On my own.
But I would appreciate it if someone would help with arduino. When I try to upload it, is says "avrdude: stk500_getsync() : not in sync: resp=0x30" What exactly does that mean and how do I fix it; because I think it has something to do with "ArrayIndexOutOfBoundsException: 1
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 sketch_jan20a.setup(sketch_jan20a.java:59)
at processing.core.PApplet.handleDraw(Unknown Source)
at processing.core.PApplet.run(Unknown Source
at java.lang.Thread.run(Thread.java:662)" on processing.
(btw: "sketch_jan20a." is the name of the processing page I put the code on) If someone could help with either or both of these, it would be much appreciated!
Doctor_Donna says: Jan 21, 2013. 10:03 PM
On processing, it says

"Cannot find a class or type named 'BeatListener'"

How do I fix this? What am I missing? No ones' answers are helping me.
landsharkxx says: Jan 5, 2013. 6:42 PM
I need help, when I press the run button in processing it says No library found for cc.arduino
Libraries must be installed in a folder called "libraries" inside the "sketchbook" folder.
I've found the libraries folder in the arduino-1.0.3 folder but I cant find sketchbook folder
gthorsnes says: Dec 14, 2012. 11:06 PM
To everyone getting the "IllegalAccess" message: go back to the Processing download page, and download the LAST KNOWN GOOD COPY: 1.5.1 For some reason the beta of 2.0 is messed up and causes this issue. Just download the 1.5.1 build, underneath the beta builds, and re-try. This fixed the issue for me.
rynev33 says: Dec 7, 2012. 10:25 AM
I am also getting that exception in thread message. Can you please explain the fix?
ejogion says: Nov 19, 2012. 6:42 PM
I got this
Exception in thread "AWT-EventQueue-0" java.lang.IllegalAccessError: tried to access class processing.core.PApplet$RegisteredMethods from class cc.arduino.Arduino$SerialProxy

HELP!!!!
pablopeillard in reply to ejogionNov 21, 2012. 3:08 PM
https://github.com/pardo-bsso/processing-arduino That fixed it for me
dannyelloko20 says: Oct 26, 2012. 3:42 PM
I got everything accordingly to what you have but im getting the following error:

OpenGL error 1280 at top beginDraw(): invalid enumerant

Help please
Sushant08 says: Jun 9, 2012. 12:33 AM
i keep getting java arrayindexoutofbounds exception1 even after i have changed the filename and added the arduino libraries
Sushant08 says: Jun 9, 2012. 12:31 AM
i keep getting java arrayindexout of exception 1 error .even after i have replaced the filename and added the arduino libraries
Dannyboy1891 says: Apr 23, 2012. 8:27 PM
Hey I am making this project for my class and I am wondering if anyone knows how i could do this same thing but with 5 led's tied in series......please comment back thanks :)
robinsunny in reply to Dannyboy1891Apr 30, 2012. 2:10 PM
same here, i'm gonna follow this thread in case anything comes up
Dannyboy1891 in reply to robinsunnyMay 1, 2012. 8:12 AM
I found out an easy way to do it without using any extra components.......just tie the led's in parallel instead of series......the arduino powered all 5 of my led's just fine make sure you have a resistor though.
robinsunny in reply to Dannyboy1891May 2, 2012. 11:38 AM
do u know a way to split the bands even more so the kick has its own lows, mids, and highs and the snare would have its own lows, mids, highs and so on? what do i need to edit to recognize more frequency ranges?
Dannyboy1891 in reply to robinsunnyMay 14, 2012. 5:27 PM
No I havent figured that out yet either. If you find out please let me know. It would better my project.
agian says: May 1, 2012. 10:41 AM
Is it possible to save the data from processing so it doesnt need to be tethered to the computer?
robinsunny says: Apr 30, 2012. 2:13 PM
how can i edit beatwriter to recognize just more than kick, snare, and hat? i want to split the lows, mids, and highs into 2 or more signals each and use 6 to 9 LEDs altogether
Sentinel07 says: Nov 22, 2010. 6:18 AM
OK here is a new problem my friend is trying to get the processing to work but he keeps getting NullPointerException and the instruction "song.play();" keeps get highlighted any suggestions Hyrulian.
Hyrulian (author) in reply to Sentinel07Nov 22, 2010. 7:16 AM
It sounds to me like your friend doesn't have the .mp3 file loaded correctly. Tell him to make sure that he's typed the filename correctly in the "song = minim.loadFile("freebird.mp3", 2048);" line. Also, tell him to make sure that the .mp3 file is located in the "BeatWrite/data" folder, not the "BeatWrite" folder.

~Hyrulian
robinsunny in reply to HyrulianApr 30, 2012. 1:37 PM
i have the same problem, but i can't get mine to work at all. the file is in the right place, and the code is edited accordingly. Every time i "run" it, it keeps giving me the same error and goes back to this line. any thoughts?
jin_yeugh in reply to HyrulianFeb 26, 2012. 7:56 PM
I just tried moving the folder around and didn't realize that it had to be in the same folder as the BeatWrite file. I had it in the same zipped folder, but separate from the file. It works great now! Thanks for the pointer.
ringofrizz says: Jan 26, 2011. 5:04 PM
Help me please, I'm a noob! :(

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.
oldsmarracin in reply to ringofrizzApr 26, 2012. 7:35 PM
arduino = new Arduino(this, Arduino.list()[0], 57600);
try that
Hyrulian (author) in reply to ringofrizzJan 26, 2011. 8:51 PM
Hi ringoffrizz,

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
ringofrizz in reply to HyrulianJan 26, 2011. 10:31 PM
My code looks like this now if it helps :)


/**
* 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();}
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 in reply to HyrulianJan 26, 2011. 10:29 PM
Thank U soooooooo much for the help Hyrulian, thank U for your fast response also!

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
Hyrulian (author) in reply to ringofrizzJan 27, 2011. 7:29 AM
Hi ringofrizz,

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
ringofrizz in reply to HyrulianJan 27, 2011. 3:33 PM
Well YAY! :D haha :p

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
Hyrulian (author) in reply to ringofrizzJan 27, 2011. 8:23 PM
Haha, there's one other problem with that line, instead of

println.Arduino.list();

you should have

println(Arduino.list());

with the parentheses.

~Hyrulian
ringofrizz in reply to HyrulianJan 28, 2011. 2:38 PM
Ok, I changed it to void setup() {println(Arduino.list());

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 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());
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 (:

Hyrulian (author) in reply to ringofrizzJan 28, 2011. 3:33 PM
We're back to your original issue, here - you need a different number than "1" on this part: Arduino.list()[1]. The whole reason we're printing out the list is so you can find your Arduino in the list of serial devices. Try this code:

/**
* 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
ringofrizz in reply to HyrulianJan 28, 2011. 3:54 PM
Ok, thank U soooooooooooooooooooooooooooo much for writing i new code! :D

It seems everything works except I get

"Cannot find a class or type named "BeatListener" " on BeatListener bl; :(

-ringofrizz
Hyrulian (author) in reply to ringofrizzJan 28, 2011. 4:13 PM
Do you have the BeatListener.pde file in the same folder as the BeatWrite.pde file?

~Hyrulian
1-40 of 98Next »
Pro

Get More Out of Instructables

Already have an Account?

close

PDF Downloads
As a Pro member, you will gain access to download any Instructable in the PDF format. You also have the ability to customize your PDF download.

Upgrade to Pro today!