Lab 6

 

Description:

I created a psychedelic music player. Using processing I play a song (.wav) file. Using the pot the user can change the speed of the song. Simultaneously a music wheel starts rotating, which gets faster as the speed of the song increases, creating a visual experience similar to the visuals played by online music players.

Materials:

1 potentiometer

DC motor

CODE:

Arduino

 

/*
 * one pot fades one motor
 * modified from AnalogInput
 * by DojoDave <http://www.0j0.org>
 * http://www.arduino.cc/en/Tutorial/AnalogInput
 * 
 */
 
int potPin = 0;   // select the input pin for the potentiometer
int motorPin = 9; // select the pin for the Motor
int val = 0;      // variable to store the value coming from the sensor
void setup() {
  Serial.begin(9600);
}
void loop() {
  val = analogRead(potPin);    // read the value from the sensor, between 0 - 1024
 // Serial.println(val);
 
  analogWrite(motorPin, val/10); // analogWrite can be between 0-255
  Serial.println(analogRead(A0));
}
 
Processing
 
 
/**
 * Load File
 * This code takes a serial input using a sensor( in this case a potentiometer
 * and based on the input alters the speed of a .wav file
 * It uses an external library called Sonia to alter the sound file
 *  
 * 
 */
 
import ddf.minim.*;
import processing.serial.*;
 
// importing the external Sonia library
import pitaru.sonia_v2_9.*;
 
Sample mySample;
Serial port;
 
void setup()
{
  size(512, 200, P2D);
    Sonia.start(this); // Start Sonia engine.
  // create a new sample object.
  mySample = new Sample("beatles.wav");
  mySample.play();
  
 
  port = new Serial(this, "COM3", 9600);
  port.bufferUntil('\n');
  background(0); 
 
  
}
 
void draw()
{
  }
 
void stop()
{
  // closing Sonia class
 Sonia.stop();
 
}
 
void serialEvent (Serial p) {
 
 String inString = port.readStringUntil('\n');
 if (inString != null) {
    inString = trim(inString);
 
    int inByte = int(inString);
      println("val="+inByte);
      
      //altering speed depending on pot value
      if(inByte<50)
      {
        mySample.setSpeed(1);
      }
      else
      {
       mySample.setSpeed(inByte/10); 
      }
 
    
}
}
 
IMG_20111011_220911.jpg
0
Your rating: None