Go Down

Topic: One sound for one Push Button (Processing to Arduino) (Read 920 times) previous topic - next topic

kdlussier

Hey, i'm working on a project that requires me to have sound play from processing when i am pressing down a button in Arduino and have it turn off and be silent when i take my finger off the button.

at the moment i can get the song to play when i'm holding the button down but when i'm not pressing it there is a loud noise in the background and i can't figure out how to fix it.

the answer might be simple and i'm just not experienced enough to see it but help would really be great, here's the code:


import processing.serial.*;

import cc.arduino.*;

import ddf.minim.*;
Minim minim;
AudioPlayer groove;
Arduino arduino;

int button = 2;



void setup()
{
  size(512, 200, P3D);
arduino = new Arduino(this, Arduino.list()[0], 57600);
  minim = new Minim(this);
  groove = minim.loadFile("marcus_kellis_theme.mp3");
  arduino.pinMode(button, Arduino.INPUT);
  background(0);
}


void draw()
{
 
  if (arduino.digitalRead(button) == Arduino.LOW )
  {
    groove.loop(1);
  }
  if (arduino.digitalRead(button) == Arduino.HIGH )
  {
    groove.play();
  } else {
  if (arduino.digitalRead(button) == Arduino.HIGH )
  {
    groove.pause();
  }
}
}
void stop()
{
  // always close Minim audio classes when you are done with them
  groove.close();
  // always stop Minim before exiting.
  minim.stop();
  super.stop();
}

mungle

Hello!
I'm looking to the same and I've tryed differents solutions but no one of them works... Now I found your solution and I'm stuck at import cc.arduino. Could you please address me on how to solve the problem? It should be so simple to play an audio pressing a button with arduino but it looks something so complicated!

Thx!

Grumpy_Mike

Quote
I'm stuck at import cc.arduino
This code is not for an arduino it is for a computer running the language processing.

With this code the arduino is running firmata and is just a stupid lobotomized I/O processor.

Some people round here don't like it, hence the flood of help the OP got a year and a half ago. Also the OP did not read the how to use this forum sticky, another endearing trait.

Go Up