Loading...
  Show Posts
Pages: 1 [2] 3 4 ... 9
16  Using Arduino / Audio / Re: processing beads library on: December 03, 2012, 03:00:53 am
Yes. Sorry for not being clear!
17  Using Arduino / Audio / processing beads library on: December 03, 2012, 01:30:34 am
Hello,

I have a program I'm working on that uses the Beads library to sample songs and change the rate at which they're played (this is done using a potentiometer—I'm sending data in from an Arduino to control the rate).

In this program, the sound clip is established in the void setup() function.

However, I would like to be able to change the song sample dynamically, in void draw(), depending on what data the program is receiving. I have five different songs, and I want the Processing program to play a different song, depending on whether the values it's receiving are between 1-100, 101-200, 201-300, 301-400, or 401-500.

Here is my code so far:


Code:
import processing.serial.*;

Serial port;

float derp = 0;

// Sampling_03.pde

// this is a more complex sampler
// clicking somewhere on the window initiates sample playback
// moving the mouse controls the playback rate

import beads.*;

AudioContext ac;

SamplePlayer sp1;

// we can run both SamplePlayers through the same Gain
Gain sampleGain;
Glide gainValue;

Glide rateValue;

void setup()
{
  size(800, 600);

  port = new Serial(this, "/dev/tty.usbmodem411", 9600);
  port.bufferUntil('\n');

  ac = new AudioContext(); // create our AudioContext

    // whenever we load a file, we need to enclose the code in a Try/Catch block
  // Try/Catch blocks will inform us if the file can't be found
  try { 
    // initialize the SamplePlayer
    sp1 = new SamplePlayer(ac, new Sample(sketchPath("") + "prelude_no_8.mp3"));
  }
  catch(Exception e)
  {
    // if there is an error, show an error message (at the bottom of the processing window)
    println("Exception while attempting to load sample!");
    e.printStackTrace(); // then print a technical description of the error
    exit(); // and exit the program
  }

  // note that we want to play the sample multiple times
  sp1.setKillOnEnd(false);

  rateValue = new Glide(ac, 1, 30); // initialize our rateValue Glide object
  sp1.setRate(rateValue); // connect it to the SamplePlayer

  // as usual, we create a gain that will control the volume of our sample player
  gainValue = new Glide(ac, 0.0, 30);
  sampleGain = new Gain(ac, 1, gainValue);
  sampleGain.addInput(sp1);

  ac.out.addInput(sampleGain); // connect the Gain to the AudioContext

  ac.start(); // begin audio processing

  background(0); // set the background to black
  stroke(255);
  line(width/2, 0, width/2, height); // draw a line in the middle
  text("Click to begin playback.", 100, 100); // tell the user what to do!
  text("Move the mouse to control playback speed.", 100, 120); // tell the user what to do!
}

// although we're not drawing to the screen, we need to have a draw function
// in order to wait for mousePressed events
void draw()
{
 
  float halfWidth = width / 2.0;

  gainValue.setValue((float)mouseY / (float)height); // set the gain based on mouse position along the Y-axis
  rateValue.setValue(((float)derp - halfWidth)/halfWidth); // set the rate based on mouse position along the X-axis

  print("gain:");
  println((float)mouseY / (float)height);
  print("rate:");
  println(((float)derp - halfWidth)/halfWidth);
  print("derp:");
  println(derp);
}

// this routine is called whenever a mouse button is pressed on the Processing sketch
void mousePressed()
{
  // if the left mouse button is clicked, then play the sound
  if( mouseX > width / 2.0 )
  {
    sp1.setPosition(000); // set the start position to the beginning
    sp1.start(); // play the audio file
  }
  // if the right mouse button is clicked, then play the bass drum sample backwards
  else
  {
    sp1.setToEnd(); // set the start position to the end of the file
    sp1.start(); // play the file in reverse (rate set in the draw routine)
  }
}

void serialEvent (Serial port)
{
  derp = float(port.readStringUntil('\n'));
}

Any help would be largely appreciated! Thank you!
18  Using Arduino / Programming Questions / Re: connecting to a webpage on: November 21, 2012, 02:50:33 am
Quote
You use client code instead of server code to send a get request to the server.

zoomkat, could you please elaborate? Thanks.
19  Using Arduino / Programming Questions / connecting to a webpage on: November 21, 2012, 01:42:23 am
Hello all,

I hope I'm posting this in the right part of the forum. I know that Ethernet shields allow you to control an Arduino from a webpage, but I'm looking to do the opposite—control some dynamic jQuery and CSS content via an Arduino. Do any of you know if this is possible with an Arduino shield? If not, then how do I connect to this webpage? If it is possible, then how do I get started?

Thanks!
20  Using Arduino / Project Guidance / Elektrobiblioteka on: November 21, 2012, 01:05:38 am
Hello all,

I'm working on making a book that uses electrically conductive media, and I'm sort of modeling it after this one:

I was wondering, would any of you happen to know—or be able to make a very educated guess at—how the arduino program knows which page the user is currently on?

Thanks!
21  Using Arduino / Installation & Troubleshooting / Re: I keep getting this odd message whenever I try to upload to my Arduino Mega 2560 on: May 02, 2012, 03:44:10 pm
Do you think there is a chance I shorted that part of the board somehow?
22  Using Arduino / Installation & Troubleshooting / Re: I keep getting this odd message whenever I try to upload to my Arduino Mega 2560 on: May 02, 2012, 03:43:22 pm
I tried connecting an LED to various pins and uploading the Blink program. It worked fine for pins 13 and 8, but when I tried pins 22, 23, and 24, it didn't work. 22 and 23 were always high, no matter what, and 24 was always low.
23  Using Arduino / Installation & Troubleshooting / Re: I keep getting this odd message whenever I try to upload to my Arduino Mega 2560 on: May 02, 2012, 03:24:27 pm
Now it appears as though pins 24-53 are perpetually low, and pins 22 and 23 are perpetually high. Odd.
24  Using Arduino / Installation & Troubleshooting / Re: I keep getting this odd message whenever I try to upload to my Arduino Mega 2560 on: May 02, 2012, 03:07:09 pm
The oddest thing just happened. I just disconnected everything from my Arduino, quit Arduino on my computer, then reconnected the Arduino to my computer—without any electronics connected to the Arduino. I tried uploading the program I had been working on last night, and this time it uploaded fine. I haven't changed or done anything. I didn't even run the test. o_O
25  Using Arduino / Installation & Troubleshooting / Re: Can no longer upload ANY sketches to Arduino Mega 2560 - timeout at upload on: May 02, 2012, 03:40:29 am
Hah, no way. I just ran into the exact same problem and posted a thread about it right this second. I really hope somebody can help us figure this out. *crosses fingers*
26  Using Arduino / Installation & Troubleshooting / I keep getting this odd message whenever I try to upload to my Arduino Mega 2560 on: May 02, 2012, 03:39:22 am
I just ordered an Arduino Mega 2560, and so far, I've managed to upload programs to it successfully. However, whenever I tried using any of the extra digital pins that it comes with, they wouldn't work. I just tried using them again—specifically, here is the code I wrote before the void setup() part of my program:

Code:
int cathode01 = 22;
int cathode02 = 23;
int cathode03 = 24;
int cathode04 = 25;
int cathode05 = 26;

Then, when I tried uploading the program, I kept getting a message that said "avrdude: stk500_2_ReceiveMessage(): timeout." Now whenever I try uploading anything at all to the Mega, I receive the exact same message. I've tried holding down the reset button before uploading programs, I've tried removing the Mega from "Networks" under "System Preferences," I've tried checking the board and the serial port…but to no avail. Please help? Thanks.
27  Using Arduino / Programming Questions / Re: arduino/processing serial communication being slow on: November 13, 2011, 04:29:57 pm
Yes, that's why I changed the minimum size to 2x2 pixels.

What about the 3D, though? Is there anything I can do to improve the speed?
28  Using Arduino / Programming Questions / Re: arduino/processing serial communication being slow on: November 13, 2011, 03:02:30 pm
Code:
import processing.opengl.*;
import processing.serial.*;
Serial port;

float znoise = 0.0;
float derp;
color boxFill;

void setup() {
  size(1000,800, OPENGL);
  port = new Serial(this, "/dev/cu.usbserial-A700fiDh", 9600);
  port.bufferUntil('\n');
  noStroke();
}

void draw() {
  float x = 0;
  float y = 0;

println(derp);

  if(derp>=201 && derp<=400) {
    float herp = map(derp, 201, 400, 0, 1023);
   
   if(millis()%1000 == 0){
     rect(0,0,width,height);
     background(#ffffff);
   }
   
    boxFill = color(random(255), random(255), random(255), random(105));
    translate(400,300,0);
    rotateY(random(herp));
    rotateX(random(herp));
    fill(boxFill);
    box(random(herp), random(herp), random(.5*(herp+herp)) );

   // println(herp);
  }

  if(derp>=0 && derp<=200) {

    float herp = map(derp, 0, 200, 0, 1023);

    if(herp>500) {
      x=20;
      y=20;
    }
    else if(herp>350 && herp<=500) {
      x = 10;
      y=10;
    }
    else if(herp<=350 && herp>100) {
      x=6;
      y=6;
    }
    else if(herp<=120 && herp>90) {
      x=5;
      y=5;
    }
    else if(herp<=90 && herp>60) {
      x=4;
      y=4;
    }
    else if(herp<=60 && herp>30) {
      x=3;
      y=3;
    }
    else if(herp<=30) {
      x=2;
      y=2;
    }

    float xnoise = 0.0;
    float ynoise = 0.0;
    for(int i=0; i<=height; i+=y) {
      for(int j=0; j<=width; j+=x) {
        float blah = noise(xnoise, ynoise, znoise)*256;
        fill(blah);
        rect(j, i, x,y);

        if(key=='c' || key == 'C') {
          fill(i, blah, j);
          rect(j, i, x,y);
        }

        xnoise += 0.09;
      }
      ynoise += 0.09;
    }
    znoise += 0.09;
   
   
  //println(herp);
  }
}

void serialEvent (Serial port)
{
  derp = float(port.readStringUntil('\n'));
}
29  Using Arduino / Programming Questions / Re: arduino/processing serial communication being slow on: November 13, 2011, 01:59:02 pm
Heh, I'm not always that good at picking up hints.

Are you referring to the 3D part of my Processing code? Here it is:

Code:
  if(derp>=201 && derp<=400) {
    float herp = map(derp, 201, 400, 0, 1023);
   
   if(millis()%1000 == 0){
     rect(0,0,width,height);
     background(#ffffff);
   }
   
    boxFill = color(random(255), random(255), random(255), random(105));
    translate(400,300,0);
    rotateY(random(herp));
    rotateX(random(herp));
    fill(boxFill);
    box(random(herp), random(herp), random(.5*(herp+herp)) );

   // println(herp);
  }
30  Using Arduino / Programming Questions / Re: arduino/processing serial communication being slow on: November 13, 2011, 12:50:18 pm
Nope.
Pages: 1 [2] 3 4 ... 9