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
// 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) } }
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?
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?
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.
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
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*
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.