0
votes

How Can I add a song to this code using processing?, And synchronize it with a PIR sensor in Arduino?.

import processing.video.*;
import ddf.minim.*;
import ddf.minim.AudioPlayer;

// Size of each cell in the grid
int cellSize = 20;
// Number of columns and rows in our system
int cols, rows;
// Variable for capture device
Capture video;
Minim minim;
AudioPlayer song;

void setup() {
size(1280, 720);
frameRate(30);
cols = width / cellSize;
rows = height / cellSize;
colorMode(RGB, 255, 255, 255, 100);

// This the default video input, see the GettingStartedCapture 
// example if it creates an error
video = new Capture(this, width, height);

// Start capturing the images from the camera
video.start();  

background(0);
}

{
// we pass this to Minim so that it can load files from the data directory
minim = new Minim(this);

// loadFile will look in all the same places as loadImage does.
// this means you can find files that are in the data folder and the 
// sketch folder. you can also pass an absolute path, or a URL.
song = minim.loadFile("untitled.wav");
}


void draw() { 
if (video.available()) {
video.read();
video.loadPixels();

// Begin loop for columns
for (int i = 0; i < cols; i++) {
  // Begin loop for rows
  for (int j = 0; j < rows; j++) {

    // Where are we, pixel-wise?
    int x = i*cellSize;
    int y = j*cellSize;
    int loc = (video.width - x - 1) + y*video.width; // Reversing x to mirror       the image

    float r = red(video.pixels[loc]);
    float g = green(video.pixels[loc]);
    float b = blue(video.pixels[loc]);
    // Make a new color with an alpha component
    color c = color(r, g, b, 75);

    // Code for drawing a single rect
    // Using translate in order for rotation to work properly
    pushMatrix();
    translate(x+cellSize/2, y+cellSize/2);
    // Rotation formula based on brightness
    rotate((2 * PI * brightness(c) / 255.0));
    rectMode(CENTER);
    fill(c);
    noStroke();
    // Rects are larger than the cell for some overlap
    rect(0, 0, cellSize+6, cellSize+6);
    popMatrix();
  }
  }
  }
  }

I am interested to detect the movement to activate or desactivate this feature. Please, Can you help me.

This is the error that I got:

The sketch path is not set. ==== JavaSound Minim Error ==== ==== java.lang.reflect.InvocationTargetException

=== Minim Error === === Couldn't load the file untitled.wav

1
I have this code for the audio and it works: import ddf.minim.*; import ddf.minim.AudioPlayer; Minim minim; AudioPlayer song; void setup() { background(0, 0, 0); //p2 play sound file //Construct a new instance of minim minim = new Minim(this); //Load the file we want to play song = minim.loadFile("data/untitled.wav"); //play the file song.play(); } void draw() { background(0); } - user2718102
Solved!, How Can I synchronize the Arduinio PIR sensor with Porcessing?. - user2718102
With this code, How Ca I add a layer 0f video to the webcam feature?. - user2718102

1 Answers

0
votes

Stack Overflow isn't really designed for general "how do I do this" type questions. It's for specific "I tried X, expected Y, but got Z instead" type questions. But I'll try to help in a general sense:

You need to break your problem down into smaller pieces and then take those pieces on one at a time. Get a simple example working. If you're asking about audio, then forget about the webcam for a second. Create a simple sketch that just plays a sound. Separately from that, create a simple sketch that just gets a webcam working. When you have those working perfectly, then you can think about combining them. But work your way forward in small steps. Write down exactly what you want to happen, in English, and that will be an algorithm that you can think about implementing with code.

Then if you get stuck, you can post a more specific question along with a MCVE. Good luck.