hello , for a project I'm currently working on I'm using servo (atm may switch to solenoids) to play notes on a physical instrument. I tried using midi as a way of storing songs and telling the arduino which notes to play (which servos to write to what positions) But i didn't progress very far with the tutorials and I am quite pushed for time.
my solution was to laboriously transcribe the songs I had written into a long list of servo.write commands. however another part of the project is that I want users to be able to control one other servo independantly while the other servo's play the songs. the problem with this I've just realised is my code is obviously full of delays.
the code below is representative of the way tracks will be played by the servos but does not feature the control structures I will be using to initiate these sequences , these are in another sketch which is still in development.
#include <Servo.h>
Servo C3; // create servo object to control a servo
Servo D3; // each servo object correpsonds to it's note
Servo E3;
Servo G3;
Servo B3;
Servo D4;
Servo F3;// a maximum of eight servo objects can be created
void setup()
{
C3.attach(9); // attaches the servos to different pins on the arduino
D3.attach(8);
E3.attach(7);
G3.attach(6);
B3.attach(5);
D4.attach(4);
F3.attach(3);
}
void loop()
{
B3.write (110);
G3.write (110);
D3.write (110);
delay (150);
B3.write (60);
G3.write (60);
D3.write (60);
delay (300);
B3.write (110);
delay (150);
B3.write (60);
delay (300);
B3.write (110);
F3.write (110);
delay (150);
B3.write (60);
F3.write (60);
delay (150);
D4.write (110);
delay (150);
D4.write (60);
delay(300);
B3.write (110);
G3.write (110);
D3.write (110);
delay (150);
B3.write (60);
G3.write (60);
D3.write (60);
delay (300);
B3.write (110);
delay (150);
B3.write (60);
delay (300);
B3.write (110);
F3.write (110);
C3.write (110);
delay (150);
B3.write (60);
F3.write (60);
C3.write (60);
delay (300);
B3.write (110);
}
I looked a bit at the mills function and I thought I could try something like
if (condition to start song sequence:this will be a string name being altered by the user via a website)
millis =0
if mills = (the time in the track where the first note is play)
servo.write(110)
ect ect
I thought that this way mills would always be set to zero at the beginning of any song and i then I could use the time in micro seconds to count when the servos need to strike the instrument ?
I can't test this properly yet as I don't have my servos. is this a plausible way round my problem or am I way of the mark , I have never used mills before ?
for a little extra clarity the user will see on the webpage an interface allowing them to select track but also a live camera and audio stream the mic and cam of which I want to mount on a servo or d.c motor to allow them to rotate their perspective , This is also important because the audio stream will be binaural.
thanks very much
sam