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.<em>;
Serial myPort; // Create object from Serial class
static String val; // Data received from the serial port
int sensorVal =0;
//import processing.video.</em>;
//Movie myMovie;

PImage singe;

void setup() {
size(1920, 1080);
// myMovie = new Movie(this, "gradient.mov");
[//myMovie.play](https://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 !

Try clapping your hands and see what happens to value on the Processing side; I’m guessing that it will increase. When you know how high it goes then write code something like this:

if (value > someNumber){
image(myImage, x, y);
}

i.e., if number is above a certain value, display my image.
You can read how to load and display an image here: https://processing.org/reference/image_.html

Hi Sir

https://www.arduino.cc/education/visualization-with-arduino-and-processing

1631801284-tutorials4e022