Pages: [1]   Go Down
Author Topic: One sound for one Push Button (Processing to Arduino)  (Read 409 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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();
}
Logged

Pages: [1]   Go Up
Jump to: