We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi, I have a sketch which listens to arduino and when it reads incoming bytes then plays sounds. I am having hard time changing that to play video instead. Could you please advice me.
import processing.serial.*;
import ddf.minim.*;
Minim minim;
AudioPlayer player;
int loopcount;
int bgcolor; // Background color
int fgcolor; // Fill color
Serial myPort; // The serial port
int[] serialInArray = new int[3]; // Where we'll put what we receive
int serialCount = 0; // A count of how many bytes we receive
int xpos, ypos; // Starting position of the ball
boolean firstContact = false; // Whether we've heard from the microcontroller
void setup() {
size(256, 256); // Stage size
noStroke(); // No border on the next thing drawn
minim = new Minim(this);
printArray(Serial.list());
String portName = Serial.list()[0];
//myPort = new Serial(this, "/dev/cu.usbmodem1510721", 9600);
myPort = new Serial(this, "/dev/cu.HC-05-DevB", 9600);
}
void draw() {
background(bgcolor);
fill(fgcolor);
// Draw the shape
}
void serialEvent(Serial myPort) {
int inByte = myPort.read();
if (firstContact == false) {
if (inByte == 'A') {
player = minim.loadFile("drumgroove_3.wav");
player.loop();
// ask for more
}
if (inByte == 'F'){
player = minim.loadFile("sound_7.mp3");
player.play();
}
if(inByte == 'B'){
player = minim.loadFile("sound_2.mp3");
player.play();
}
if (inByte == 'C'){
player = minim.loadFile("sound_6_converted.wav");
player.loop(2);
loopcount = 3;
}
if (inByte == 'D'){
player = minim.loadFile("sound_4.mp3");
player.play();
}
if (inByte == 'E'){
player = minim.loadFile("sound_5.mp3");
player.play();
}
}
}
Answers