I'm using a H-bridge motor controller to control a linear actuator with potentiometer position feedback.
Here is the code:
int actpos; //actuator position off blue wire
const int motA = 10; //motor A trigger
const int motB = 12; //motor B triggervoid setup() {
// initialize serial communications:
Serial.begin(9600);pinMode(motA, OUTPUT);
pinMode(motB, OUTPUT);}
void loop() {
digitalWrite(motA, HIGH);
digitalWrite(motB, LOW);delay(2000);
actpos = analogRead (A3);
Serial.print(actpos);
Serial.println();digitalWrite(motA, LOW);
digitalWrite(motB, HIGH);delay(100);
digitalWrite(motA,HIGH);
digitalWrite(motB,HIGH);actpos = analogRead (A3);
Serial.print(actpos);
Serial.println();
}
But when I run it, it doesn't do anything like I expected. First it pulls the actuator all the way in and waits two seconds Then it moves it out slightly waits a tiny bit, moves it OUT again slightly, waits a tiny bit, moves OUT slightly again, over and over until fully extended. Then retracts and waits two seconds. How is this possible with the above code? I'm completely flummoxed.
The purpose of the program was to try to brake the actuator. Right now, it turns on the motor, but when the pins go high high, the motor coasts to a stop. I need it to brake. But it keeps going! I'm lost.