How can I play an audio using Processing depending on speed measured by sensors?

edited May 2017 in Arduino

I've connected two PIR sensors to an arduino and I have programmed it on Arduino IDE such that the Serial monitor calculated the speed of the object by measuring time of detection from each sensor. I want to play a specific audio from the laptop for a certain speed. How can I use Processing to do that? Since it has an option to play audios and IDE does not.

Tagged:

Answers

  • It's probably best to cut the problem into smaller subproblems.

    • Look at the examples of the sound library in Processing. Can you manage to play an audio file?

    • Can you modify an example in such a way that it plays an audio file when you eg. click with the mouse or hit a keyboard key?

    • Can you play multiple audio files and trigger them with different keyboard keys?

    • Can you receive the speed value in Processing using the Serial library and print it to the console?

    • Can you write a criterium for which audio file you want to play for which range of speeds? Like if speed is 0-10, play file 1, if speed is 11-20, play file 2, ...

    • Can you implement the logic to select the correct audio file?

    • And finally, put everything together!

  • @colouredmirrorball That's how I'm going about it; and I'm currently stuck at getting the speed value. I can't print it to the console.

  • edited May 2017

    @Usama1034 -- Is your Arduino sketch already sending the speed value over serial?

    If so, for an example of how to receive that value in a Processing sketch over serial, look at the PDE Examples sketch:

    Processing > Examples > Libraries > Serial > SimpleRead.pde

  • @jeremydouglass I checked that out. But that way, I keep getting values in bytes, not the calculated speed I had in IDE; or the millis() value of detection time.

Sign In or Register to comment.