dear bluesbud
i had been following your post since the very beginning. I am very much interested in your project. Okay I see that you need a 3 position application rite. i cant help up much with TouchOSC but i can help you with the H-bridge and arduino part.
first of all if you don't already have a motor driver i would suggest you to look up on this 2 link i have for you
http://www.modularcircuits.com/blog/articles/old-h-bridge-secrets/part-1/
http://www.societyofrobots.com/member_tutorials/book/export/html/159
disclaimer: I am not in anyway associated with the author of both web page.
now down to the programming part
pos = map(pos, 0, 1023, 0, 110); //remap positioning to scale of 0-100
Well if you comment is right then your program is wrong.
it should be
pos = map(pos, 0, 1023, 0, 100); //remap positioning to scale of 0-100
but how ever i would say that if you need any only 3 location
lets say I'm using 3 button and your slider which your slider have a motor controller and a linear potentiomenter as feedback.
let say in my set up,
1)if i press the first button, the motor will rotate clockwise and stop at the far end
2)if i press the second button, the motor will rotate anticlockwise and stop at the middle end if its at the far end or if its at the near end it will rotate clockwise and stop at the middle
3)if i press the third button, the motor will rotate anticlockwise and stop at the near end
this is only and example for you to see the logic behind this program, i hope you could translate it to your own setup.
if this is my setup i would like to put some kind of safety or interlock.
i would like that if any two or three button are push at the same time will not make it move.
and i would also like that unless the slider have reach it preset position it will not change its course.
i would also like to make the speed of the motor to be variable so that it is capable of a going to top speed but not overshooting.
in my physical connection from arduino to the motor controller, and the potentiometer
ok i will use a 2 pin motor controller using the circuit that is show in the webpage
http://www.societyofrobots.com/member_tutorials/book/export/html/159
to control the motor, one pin is set as Enable and this one need to be pwm, while the other pin will be the direction
Enable pin will be connected to pin 3 at Uno and pin 2 will be my direction.
if direction is High then motor turn clockwise and if direction is low then motor turn anticlockwise.
this i hypothetically speaking. The speed is control by the value of pwm on the enable, the higher the pwm then the higher the speed.
for the pot i will connect the middle leg to port A0 and the other two to ground and 5 volt respectively
for the buttons, i will hook it to pin 4,5,and 6. For the purpose of this example please consider that this button all have an external circuit that have take care the debounce or this button is a perfect button that does not need to be debounce. I then also put a resistor to the ground and one of the leg of the button, and this middle position is put to the pin. This setup is call as a pull down resistor, or just pulling the pot value down to ground
Okay now for the pseudo code,
read the value from pot,
read value of button one,button two, and button three,
if value of button one high and button two and three are low then motor rotate clockwise until pot full
if value of button two high, button one and three are low and pot higher then middle value then motor rotate anticlockwise until pot middle value
if value of button two high, button one and three are low and pot lower then middle value then motor rotate clockwise until pot middle value
if button three high and button one and two are low then motor rotate anticlockwise until pot 0
if motor rotate, button value for one, two and three is low
for real code that arduino will understand
int Pot = A0;
int Button1 = 4;
int Button2 = 5;
int Button3 = 6;
int Direction = 2;
int Enable = 3;
int Clockwise = HIGH;
int Anticlockwise = LOW;
int Stop = LOW;
int potval ;
void setup()
{
pinMode (Pot,INPUT);
pinMode (Button1,INPUT);
pinMode (Button2,INPUT);
pinMode (Button3,INPUT);
pinMode (Direction,OUTPUT);
pinMode (Enable,OUTPUT);
}
void loop()
{
int PotVal = analogRead(Pot);
int Btn1 = digitalRead(Button1);
int Btn2 = digitalRead(Button2);
int Btn3 = digitalRead(Button3);
if (Btn1 == HIGH && Btn2 ==LOW && Btn3 ==LOW)
{
int Speed = map (PotVal,PotVal,1023,255,0);
do
{
analogWrite (Enable,Speed);
digitalWrite (Direction, Clockwise);
potval = analogRead(Pot);
}
while (potval <= 1023);
if (potval == 1023)
{
digitalWrite (Enable,Stop);
}
}
if (Btn2 ==HIGH && Btn1 ==LOW && Btn3 == LOW && PotVal >512)
{
int Speed = map (PotVal,PotVal,512,255,0);
do
{
analogWrite (Enable,Speed);
digitalWrite(Direction,Anticlockwise);
potval = analogRead(Pot);
}
while (potval > 511);
if (potval == 512)
{
digitalWrite (Enable,Stop);
}
}
if (Btn2 ==HIGH && Btn1 ==LOW && Btn3 == LOW && PotVal < 512)
{
int Speed = map (PotVal,PotVal,512,255,0);
do
{
analogWrite (Enable,Speed);
digitalWrite(Direction,Clockwise);
potval = analogRead(Pot);
}
while (potval < 513);
if (potval == 512)
{
digitalWrite (Enable,LOW);
}
}
if (Btn3 == HIGH && Btn1 ==LOW && Btn2 ==LOW)
{
int Speed = map (PotVal,PotVal,0,255,0);
do
{
analogWrite (Enable,Speed);
digitalWrite (Direction,Anticlockwise);
potval = analogRead(Pot);
}
while (potval >=0);
if (potval == 0)
{
digitalWrite (Enable,Stop);
}
}
}
I hope you could understand my code bluesbud, this code however just as an example of what you could do.
I hope someone could verify my code,