I've got it on its way. I made the cases into 0, 1, 2 instead of a, b, c, and am sending those numbers from Processing. Only case 2 (move motor halfway) works, but it shoots all the way forward, and only when I add high output to the enable pin right at the start of void loop(), but when I tried moving it back with my finger it's unable to go past midpoint (b/c I've tried out all the cases on the iPad via TouchOSC). So it's getting the messages but something's up with the enable pin.
const int Pot = A5; //Set the Linear Pot middle pin to Arduino A5 port
const int Enable = 9; //Set the Motor controller pin on pin 9 Arduino
const int pin1A = 6; //Set the Motor Controller pin A1 to port 6;
const int pin2A = 5; //Set the Motor Controller pin A2 to port 5;
int Target = 0; //Target is the position we want the motor to move to
int Speed = 0; //Speed Control for motor
void setup()
{
pinMode (Pot,INPUT); //Set Pot as Input
pinMode (Enable,OUTPUT); //Set Enable as Output
pinMode (6,OUTPUT); //Set A1 as Output
pinMode (5,OUTPUT); //Set A2 as Output
Serial.begin(57600); //Initialize Serial Communication at 9600 baud rate
}
void loop() {
analogWrite(Enable, 255);
if (Serial.available() > 0)
{
int inByte = Serial.read();
switch (inByte)
{
case 0:
MoveMotor(0);
break;
case 1:
MoveMotor(512);
break;
case 2:
MoveMotor(1023);
break;
// default:
// MotorStop();
// break;
}
}
}
void MoveMotor(int Target)
{
int PotVal =analogRead (Pot);
if (PotVal > Target)
{
Speed = map (PotVal,Target,PotVal,0,255);
analogWrite (Enable, Speed);
digitalWrite (pin1A, HIGH);
digitalWrite (pin2A, LOW);
}
if (PotVal < Target)
{
Speed = map (PotVal,PotVal,Target,0,255);
analogWrite (Enable, Speed);
digitalWrite (pin1A, LOW);
digitalWrite (pin2A,HIGH);
}
else
{
digitalWrite (Enable,HIGH);
digitalWrite (pin1A, LOW);
digitalWrite (pin2A, LOW);
return;
}
}
void MotorStop()
{
digitalWrite (Enable,HIGH);
digitalWrite (pin1A, LOW);
digitalWrite (pin2A, LOW);
return;
}