Sound detector + arduino + processing

hello,

I would like to create a little game for my child to discover electronics.

Unfortunately this is not my area...

I would like to be able to display an image when you clap your hands. for this I have an arduino uno and a sound detector.

here is my arduino code :
// Define hardware connections
#define PIN_GATE_IN 2
#define IRQ_GATE_IN 0
#define PIN_LED_OUT 13
#define PIN_ANALOG_IN A0

// soundISR()
// This function is installed as an interrupt service routine for the pin
// change interrupt. When digital input 2 changes state, this routine
// is called.
// It queries the state of that pin, and sets the onboard LED to reflect that
// pin's state.
void soundISR()
{
int pin_val;

pin_val = digitalRead(PIN_GATE_IN);
digitalWrite(PIN_LED_OUT, pin_val);
}

void setup()
{
Serial.begin(9600);

// Configure LED pin as output
pinMode(PIN_LED_OUT, OUTPUT);

// configure input to interrupt
pinMode(PIN_GATE_IN, INPUT);
attachInterrupt(IRQ_GATE_IN, soundISR, CHANGE);

// Display status
Serial.println("Initialized");
}

void loop()
{
int value;

// Check the envelope input
value = analogRead(PIN_ANALOG_IN);

// Convert envelope value into a message
Serial.print("Status: ");
if(value <= 10)
{
Serial.println("Quiet.");
}
else if( (value > 10) && ( value <= 30) )
{
Serial.println("Moderate.");
}
else if(value > 30)
{
Serial.println("Loud.");
}

// pause for 1 second
delay(1000);
}

and here is my processing code :

import processing.serial.;
Serial myPort; // Create object from Serial class
static String val; // Data received from the serial port
int sensorVal =0;
//import processing.video.
;
//Movie myMovie;

PImage singe;

void setup() {
size(1920, 1080);
// myMovie = new Movie(this, "gradient.mov");
//myMovie.play();
singe = loadImage("singe.png");

/////

String portName = Serial.list()[2]; //change the 0 to a 1 or 2 etc. to match your port
myPort = new Serial(this, portName, 9600);

}

void draw() {

//image(myMovie, 0, 0);

logo.resize(0, 250);
image(singe, 550 , 350);

////
if ( myPort.available() > 0)
{ // If data is available,
val = myPort.readStringUntil('\n');
}
println(val); //print it out in the console

}

//void movieEvent(Movie m) {
// m.read();
// }

Do you know how I can say on processing: display "singe" image when the sound detector detects a value ?

thank you in advance

have a good day !

Welcome to the forum

Your topic was MOVED to its current forum category which is more appropriate than the original as it has nothing to do with Installation and Troubleshooting of the IDE

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use code tags (the </> icon above the compose window) to make it easier to read and copy for examination

i'm curious about your sound detection.

looks like you're simply monitoring an analog input for several voltage levels where the MAX possibly analog value is 1024 you're recognizing 30 as loud.

what circuit are you using? a microphone thru some amplifier to a half-wave rectifier to a capacitor with some discharge resistor to ground?

looks like something will constantly appear on the serial monitor

code could be simpler and less verbose (is "quiet" necessary)?

void loop ()
{
    int value = analogRead (PIN_ANALOG_IN);

    if (30 < value)
        Serial.println ("Loud.");
    else if (20 < value)
        Serial.println ("Moderate.");
}

Is just an arduino directly connected to the sound detector sparkfun. I just take the code of the documentation Sparkfun. Ok thank you I simplify.

You know how i can tell processing to make an image appear with noise?

thank you very much !!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.