# Arduino + Processing

**URL:** <https://discourse.processing.org/t/arduino-processing/39168>\
**Category:** Electronics (Arduino, etc.)\
**Created:** [October 8, 2022, 4:06pm UTC](https://discourse.processing.org/t/arduino-processing/39168 "2022-10-08T16:06:40Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![gradientquestion](https://avatars.discourse-cdn.com/v4/letter/g/8e8cbc/32.png) [@gradientquestion](https://discourse.processing.org/u/gradientquestion)\
**Post date:** [October 8, 2022, 4:06pm UTC](https://discourse.processing.org/t/arduino-processing/39168/1 "2022-10-08T16:06:40Z")

</div>

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 :

```auto
// 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 :

```auto
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 !

---

<div class="post-metadata">

**Author:** ![svan](https://avatars.discourse-cdn.com/v4/letter/s/82dd89/32.png) [@svan](https://discourse.processing.org/u/svan)\
**Post date:** [October 9, 2022, 1:13am UTC](https://discourse.processing.org/t/arduino-processing/39168/2 "2022-10-09T01:13:23Z")

</div>

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](https://processing.org/reference/image_.html)

---

<div class="post-metadata">

**Author:** ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)\
**Post date:** [October 9, 2022, 2:10am UTC](https://discourse.processing.org/t/arduino-processing/39168/3 "2022-10-09T02:10:45Z")

</div>

Hi Sir

[https://www.arduino.cc/education/visualization-with-arduino-and-processing](https://www.arduino.cc/education/visualization-with-arduino-and-processing)

---

<div class="post-metadata">

**Author:** ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)\
**Post date:** [October 9, 2022, 3:15am UTC](https://discourse.processing.org/t/arduino-processing/39168/4 "2022-10-09T03:15:11Z")

</div>

![1631801284-tutorials4e022](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/9/6/9679b462e79f840f8eeecee17b4854c722190b11.gif)
