Quantcast
Channel: Processing Forum
Viewing all articles
Browse latest Browse all 1768

Help with Serial read

$
0
0
I'm using Arduino with Processing. So I wan't to do stuff with the Arduino on the processing program, like when it serial read such as "1" it do stuff like play a mp3 file.

Here is the code I started with, so I will when it serial read 1 it play the mp3 file:

  1. import ddf.minim.*;
  2. import processing.serial.*;

  3. Serial port;

  4. AudioPlayer PVY;
  5. Minim minim;//audio context

  6. void setup()
  7. {
  8.   size(400, 400);
  9.   minim = new Minim(this);
  10.   PVY = minim.loadFile("PVY.mp3", 2048);
  11.   PVY.play();
  12.   
  13.   port = new Serial(this, "COM3", 9600);
  14.   port.bufferUntil('\n');
  15. }

  16. void draw()
  17. {
  18.   background(255, 0, 0);
  19.   
  20. }

  21. void stop()
  22. {
  23.   PVY.close();
  24.   minim.stop();
  25.   super.stop();
  26. }

Viewing all articles
Browse latest Browse all 1768

Trending Articles