well at work I was asked to move from using pneumatic bellows in my design to servos, to add the ability to control acceleration and deceleration accurately without all the mess and size of adding several air valves.
To keep things simple, each output from our midi decoder will be sent to an input on the Arduino to control the movements of 6 servos bending 6 separate tremolos attached to 6 guitar strings. One input pin can set whether it is a full movement of the servo or a half movement (bend from A to B or from A to A#) and to keep the strings in tune, there will need to be 6 potentiometers to set the distance the servo moves for full , and 6 more for half. Also, 3 input pins to set the (could add more later) 4 speeds of movement. The speed inputs must also affect the speed the servo returns home the instant its bend input changes state, even it hasn't finished its initial movement.
My knowledge of programming basically began today, so forgive me if my attempt at coding has major holes, and most of the values are estimations, as nothing is hooked to hardware yet to get the actual values.
Also I am sure it would help the program loop faster if everything is squished into one section filled with variables instead of 6 sections for each servo, but I wanted to ask if that would create problems with initiating a 2nd action on another servo, in the middle of the first servos action. Causing a monophonic instead of polyphonic situation, for lack of a better example.
will probably use, or at least use something similar to the varspeedservo.h library to address speeds.
http://forum.arduino.cc/index.php?topic=61586.0
an example of the pneumatic mechanism it will be replacing, in use.
#include <VarSpeedServo.h>
int Tuning; // set variable to value of potentiometer
int Pot_E_Full = 0;
int Pot_A_Full = 1;
int Pot_D_Full = 2;
int Pot_g_Full = 3;
int Pot_b_Full = 4;
int Pot_e_Full = 5;
int Pot_E_Half = 6;
int Pot_A_Half = 7;
int Pot_D_Half = 8;
int Pot_g_Half = 9;
int Pot_b_Half = 10;
int Pot_e_Half = 11;
int Pos_E;
int Pos_A;
int Pos_D;
int Pos_g;
int Pos_b;
int Pos_e;
int GuitarString_E_Pin = 22;
int GuitarString_A_Pin = 24;
int GuitarString_D_Pin = 25;
int GuitarString_g_Pin = 26;
int GuitarString_b_Pin = 27;
int GuitarString_e_Pin = 28;
int BendSpeed;
int Bend_Fast_Pin = 30;
int Bend_Slow_Pin = 32;
int Bend_Long_Pin = 34;
int Half_to_Full_Note_Pin = 36;
int High_Position = 160;
int Low_Position = 0;
VarSpeedServo Servo_E;
VarSpeedServo Servo_A;
VarSpeedServo Servo_D;
VarSpeedServo Servo_g;
VarSpeedServo Servo_b;
VarSpeedServo Servo_e;
//Servo_E.attach (mainPin, ServoMin, ServoMax);
//Servo_E.slowmove (newpos, speed);
//1 slowest, 255 fastest (not noticeable above 127)
void setup() { // put your setup code here, to run once:
pinMode(GuitarString_E_Pin, INPUT);
pinMode(GuitarString_A_Pin, INPUT);
pinMode(GuitarString_D_Pin, INPUT);
pinMode(GuitarString_g_Pin, INPUT);
pinMode(GuitarString_b_Pin, INPUT);
pinMode(GuitarString_e_Pin, INPUT);
pinMode(Bend_Fast_Pin, INPUT);
pinMode(Bend_Slow_Pin, INPUT);
pinMode(Bend_Long_Pin, INPUT);
pinMode(Half_to_Full_Note_Pin, INPUT);
Servo_E.attach (2, High_Position, Low_Position);
Servo_A.attach (3, High_Position, Low_Position);
Servo_D.attach (4, High_Position, Low_Position);
Servo_g.attach (5, High_Position, Low_Position);
Servo_b.attach (6, High_Position, Low_Position);
Servo_e.attach (7, High_Position, Low_Position);
}
void loop() {
if ((GuitarString_E_Pin == HIGH), (Half_to_Full_Note_Pin == HIGH)) {
Tuning = analogRead(Pot_E_Full) / 10; // read the tuning value
if (Pos_E <= 80) {
Servo_E.slowmove (81 * Tuning, BendSpeed + 1);
}
else {
Servo_E.slowmove (150 * Tuning, BendSpeed + 21);
}
}
else {
if (Pos_E >= 81) {
Servo_E.slowmove (80 * Tuning, BendSpeed + 1);
}
else {
Servo_E.slowmove (0, BendSpeed + 21);
delay (50);
}
}
if ((GuitarString_E_Pin == HIGH), (Half_to_Full_Note_Pin == LOW)) {
Tuning = analogRead(Pot_E_Half) / 10; // read the tuning value
if (Pos_E <= 50) {
Servo_E.slowmove (51 * Tuning, BendSpeed + 1);
}
else {
Servo_E.slowmove (90 * Tuning, BendSpeed + 21);
}
}
else {
if (Pos_E >= 51) {
Servo_E.slowmove (50 * Tuning, BendSpeed + 1);
}
else {
Servo_E.slowmove (0, BendSpeed + 21);
delay (50);
}
}
//everything from line 64 to 99 repeated for each guitar string
//after making sure it actually works
if (Bend_Fast_Pin == HIGH) { //check bend speed
BendSpeed = 0;
}
if ((Bend_Fast_Pin == LOW) && (Bend_Slow_Pin == LOW) && (Bend_Long_Pin == LOW)) {
BendSpeed = 60;
}
if (Bend_Slow_Pin == HIGH) {
BendSpeed = 20;
}
if (Bend_Long_Pin == HIGH) {
BendSpeed = 1;
}
}