Go Down

Topic: audio (Read 771 times) previous topic - next topic

arduinoadrian

Oh Ok. Sorry. Will post again.

Check this out.

In these threads you will find answers to most of the same questions. They were discussed here recently.

http://arduino.cc/forum/index.php/topic,93323.msg703752.html#msg703752
http://arduino.cc/forum/index.php/topic,101231.0.html
Perseverance is 90% of the solution. The remaining 10% is more perseverance.

oddthumb

#6
Apr 17, 2012, 01:04 pm Last Edit: Apr 17, 2012, 01:05 pm by oddthumb Reason: 1
:D thanks everyone (and i have deleted the other posts-- sorry!)

i'm using a LDR to turn the LED on without light
and the LED will trigger the Servo Motor to a certain degree of angle.

since i cannot find much information with what i originally wanted to do with the sound,

i've decided to get a Waveshield and SD/MMC card to play the sound from the library as the motor moves.

Hopefully it will work.. and arrive in time! :)

oddthumb

#7
Apr 18, 2012, 12:31 pm Last Edit: Apr 18, 2012, 12:33 pm by oddthumb Reason: 1
As I have not enough time to wait for the waveshield
I tried to find another way of playing the music file.

But im getting an error ;<

This is the code I used:-

#include <Servo.h>
import ddf.minim.*;
import processing.serial.*;

#define MOTOR 4 //motor is plugged in to pin 4
#define SENSOR 7 //button is plugged in to pin 7
#define LED 13

int trigger = 1;//if button's not pressed, trigger = 0, else trigger = 1

Minim minim;
AudioPlayer player;

Servo myservo;

void setup()//initializing
{

minim = new Minim(this);
player = minim.loadFile("filename.mp3",2048);

port = new Serial(this, Serial.list()[MOTOR],9600);

size(10,10);

myservo.attach(MOTOR);

pinMode(LED , OUTPUT);
pinMode(SENSOR , INPUT);
//setting button(7) as an INPUT
}


int move = 0;//movement of the motor in degrees(angle)


void loop()
{
trigger = digitalRead(SENSOR);
//checks if the button is pressed or not

if(trigger == 0)//if the sensor detects darkness
{//move the motor

digitalWrite(LED , HIGH);

delay(2000);//wait for 2 seconds

//moves the motor 30 degrees 0 to 30
//move += 1 increments the value of move by 1
for(move = 0; move < 30; move += 1)
{
myservo.write(move);//move the motor by the given value

delay(4);//waits for 4ms
}//end of for

player.play();

delay(1000); //wait for 1 sec

//this for loop moves back the position of the motor from 30 degrees to 0
//move -= 1 decrements value of move by 1
for(move = 30; move >= 0; move -= 1)
{
myservo.write(move);
delay(5);
}
delay(1000);

}//end of if
else
digitalWrite(LED , LOW);


}

void stop()
{
player.close();

minim.stop();

super.stop();

}


The error msg says, import does not name a type???
I'm not sure what im doing wrong :S

dxw00d

#8
Apr 18, 2012, 12:47 pm Last Edit: Apr 18, 2012, 12:52 pm by dxw00d Reason: 1
You appear to be trying to compile a cross between Processing code and Arduino code in the Arduino IDE.

Minim is a library for Processing.
Servo.h is a library for Arduino.

oddthumb

#9
Apr 18, 2012, 01:01 pm Last Edit: Apr 18, 2012, 01:11 pm by oddthumb Reason: 1
;( will i have to use something like Firmata to do this????????????
(sorry im new to all of this @@)

Go Up