I am using Arduino 1.0.5. I uploaded the StandardFirmata sketch onto my mega, here is my processing sketch:
import ddf.minim.*;
import ddf.minim.ugens.*;
import processing.serial.*;
import cc.arduino.*;
//this object represents your board
Arduino arduino;
//this is the minim environment
Minim minim;
AudioOutput out;
AudioPlayer cow;
AudioPlayer sheep;
AudioPlayer unicorn;
AudioPlayer frog;
AudioPlayer dinosaur;
Oscil osc;
Delay myDelay;
Midi2Hz midi;
//this is the object that plays your file
AudioPlayer player;
AudioPlayer player2;
//use variables for pin numbers
int sensorPin = 0;
//led pin
int SPACE_PIN = 51;
int SPACE_PIN2 = 49;
int SPACE_PIN3 = 47;
int SPACE_PIN4 = 45;
int SPACE_PIN5 = 43;
int SPACEREDLED_PIN = 52;
//button
int photosensorPin = 7;
int photoResistorPin = 1;
int photoResistorPin2 = 2;
int cowPin = 3;
int sheepPin = 4;
int unicornPin = 5;
int frogPin = 7;
int dinosaurPin = 6;
//this is the minimum value from the sensor that will trigger the sound
int threshold = 300;
int photoThreshold = 150;
int photoThreshold2 = 150;
int cowThreshold = 250;
int sheepThreshold = 450;
int unicornThreshold = 250;
int frogThreshold = 250;
int dinosaurThreshold = 250;
float threshold2 = 0.5;
float photoresistor=0;
int photoresistorLed=0;
float photoresistor2=0;
int photoresistorLed2=0;
void setup()
{
size(640, 200);
//the arduino object needs to be created at the beginning
println(Arduino.list());
arduino = new Arduino(this, Arduino.list()[4], 57600);
arduino.pinMode(SPACE_PIN, Arduino.OUTPUT);
arduino.pinMode(SPACE_PIN2, Arduino.OUTPUT);
arduino.pinMode(SPACE_PIN3, Arduino.OUTPUT);
arduino.pinMode(SPACE_PIN4, Arduino.OUTPUT);
arduino.pinMode(SPACE_PIN5, Arduino.OUTPUT);
arduino.pinMode(SPACEREDLED_PIN, Arduino.OUTPUT);
//initialize minim
minim = new Minim(this);
// initialize myDelay with continual feedback and audio passthrough
myDelay = new Delay( 0.4, 0.5, true, true );
out = minim.getLineOut();
osc = new Oscil( 440, 0.5 );
cow = minim.loadFile("moo.wav");
sheep = minim.loadFile("baa.mp3");
unicorn = minim.loadFile("horse.mp3");
frog = minim.loadFile("frog.mp3");
dinosaur = minim.loadFile("dinogrowl.wav");
}
void draw()
{
size(512, 200);
//stop led being on constantly
arduino.digitalWrite(SPACE_PIN, Arduino.LOW);
arduino.digitalWrite(SPACE_PIN2, Arduino.LOW);
arduino.digitalWrite(SPACE_PIN3, Arduino.LOW);
arduino.digitalWrite(SPACE_PIN4, Arduino.LOW);
arduino.digitalWrite(SPACE_PIN5, Arduino.LOW);
arduino.digitalWrite(SPACEREDLED_PIN, Arduino.LOW);
//define photoresistor
photoresistor = arduino.analogRead(0);
//define photoresistor
//potentiometer = arduino.analogRead(0);
//photoresistor with delay osc sounds for space
float value = map(photoresistor,200,1700,0,16000);
osc.setFrequency(value);
//ufo
int photoResistorValue = arduino.analogRead(photoResistorPin);
// println(photoResistorValue); //print it for testing purposes
//if photoresistor is greater than 100, turn on LED
if (photoResistorValue > photoThreshold)
{
//turn on LED
arduino.digitalWrite(SPACEREDLED_PIN, Arduino.HIGH);
}
//stars
int photoResistorValue2 = arduino.analogRead(photoResistorPin2);
//println(photoResistorValue2); //print it for testing purposes
//if photoresistor is greater than 100, turn on LED
if (photoResistorValue2 > photoThreshold2)
{
//turn on LED
arduino.digitalWrite(SPACE_PIN, Arduino.HIGH);
arduino.digitalWrite(SPACE_PIN2, Arduino.HIGH);
arduino.digitalWrite(SPACE_PIN3, Arduino.HIGH);
arduino.digitalWrite(SPACE_PIN4, Arduino.HIGH);
arduino.digitalWrite(SPACE_PIN5, Arduino.HIGH);
}
//cow noise
//read an analog value from the sensor pin
int cowValue = arduino.analogRead(cowPin);
//println(cowValue); //print it for testing purposes
//check if the reproduction is in process if not don't trigger another sound
if ( cow.isPlaying() == false && cowValue > cowThreshold)
{
cow.rewind();
cow.play();
}
//sheep noise
int sheepValue = arduino.analogRead(sheepPin);
//println(sheepValue); //print it for testing purposes
//check if the reproduction is in process if not don't trigger another sound
if ( sheep.isPlaying() == false && sheepValue > sheepThreshold)
{
sheep.rewind();
sheep.play();
}
//unicorn noise
//cow noise
//read an analog value from the sensor pin
int unicornValue = arduino.analogRead(unicornPin);
// println(unicornValue); //print it for testing purposes
//check if the reproduction is in process if not don't trigger another sound
if ( unicorn.isPlaying() == false && unicornValue > unicornThreshold)
{
unicorn.rewind();
unicorn.play();
}
int dinosaurValue = arduino.analogRead(dinosaurPin);
println(dinosaurValue); //print it for testing purposes
//check if the reproduction is in process if not don't trigger another sound
if ( dinosaur.isPlaying() == false && dinosaurValue > dinosaurThreshold)
{
dinosaur.rewind();
dinosaur.play();
}
//frog noise
//read an analog value from the sensor pin
int frogValue = arduino.analogRead(frogPin);
println(frogValue); //print it for testing purposes
//check if the reproduction is in process if not don't trigger another sound
if ( frog.isPlaying() == false && frogValue > frogThreshold)
{
frog.rewind();
frog.play();
}
//drawings
// erase the window to black
background( 0 );
// draw using a white stroke
stroke( 255 );
// draw the waveforms
for( int i = 0; i < out.bufferSize() - 1; i++ )
{
// find the x position of each buffer value
float x1 = map( i, 0, out.bufferSize(), 0, width );
float x2 = map( i+1, 0, out.bufferSize(), 0, width );
// draw a line from one buffer position to the next for both channels
line( x1, 50 + out.left.get(i)*50, x2, 50 + out.left.get(i+1)*50);
line( x1, 150 + out.right.get(i)*50, x2, 150 + out.right.get(i+1)*50);
}
//end of drawings
}
void stop()
{
minim.stop();
super.stop();
}
In this sketch I have 8 photo resistors working as sensors to control an oscillator, LED's and sound files. Everything works perfectly until I go past pin A5