Sound detector + processing

Bonjour,
J'aimerais faire un petit jeu à mon enfant pour qu'il voit les possibilités avec l'électronique mais moi je ne connais absolument pas grand-chose...

J'aimerais pouvoir afficher une image sur Processing lorsqu'on clap des mains.
Pour cela j'ai un sound detector sparfun - arduino uno.

J'utilise ce code sur arduino :

// 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);
}```




et celui-ci sur processing :

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

  singe.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();
//  }  ```

mais je n'ai vraiment aucune idée sur comment dire à processing d'afficher l'image quand il y a eu un son detecté, et je ne trouve pas grand-chose sur github ou autre. Avez-vous des idées sur comment je peux faire ?
je vous remercie énormément d'avance pour votre aide

bonne journée :slight_smile:

Bonjour

Sur le site MonClubElec on trouve pas mal de choses en langue française pour Processing y compris içi pour une laison série avec une carte Arduino :
https://www.mon-club-elec.fr/pmwiki_mon_club_elec/pmwiki.php?n=MAIN.OUTILSProcessing#toc44

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