right i have had a play with your example and mingle some of my bits in as i have to look at the limits and enable for the H-bridge as well.
let me no what you think and if i am going the right way?
tammytam:
// keep both sensorValue and where in range of 0 to 1023, get the delta then shift down by 2, which
// effectively divides by 4 (more importantly takes your 0-1023 range into 0-255 that the PWM takes
int motorSpeed = ( controlPot - MotorPot ) >> 2;
motorSpeed = motorSpeed < 5 ? 0 : motorSpeed; // NEW LINE, should remove hunting
// one way
if (digitalRead(vent1UPlim)== HIGH) {
analogWrite(vent1PWMB , 0 );
digitalWrite(vent1enable, HIGH);
delay(50);
analogWrite(vent1PWMA ,motorSpeed);
mydisp.drawStr(0, 2, "-close-|");
} else {
analogWrite(vent1PWMA , 0 );
delay(50);
digitalWrite(vent1enable, LOW);
mydisp.drawStr(0, 2, " |");
}
// other way
if (digitalRead(vent1DOWNlim)== HIGH) {
analogWrite(vent1PWMA , 0 );
digitalWrite(vent1enable, HIGH);
delay(50);
analogWrite(vent1PWMB ,motorSpeed);
mydisp.drawStr(0, 2, "-open -|");
} else {
analogWrite(vent1PWMB , 0 );
delay(50);
digitalWrite(vent1enable, LOW);
mydisp.drawStr(0, 2, " |");
}
// disabled drivers when not being used
if (motorSpeed > 5) {
digitalWrite(vent1enable, LOW);
mydisp.drawStr(0, 2, " |");
}
Rx7man:
int MaxSpeed = 255; //The maximum speed you want to run at.. perhaps you want to not run at full speed.. values are from 0-255;
int FullSpeedPotDifference = 100; //when the values are more than this apart, you will be running at MaxSpeed
//The motor will linearly slow down from there to the deadband point, where it will stop
int Deadband = 3; //No motor output if the pots are within this value of each other
int motorPot = analogRead(InputPin1); //the pot your motor is mechanically controlled to
int controlPot = analogRead(InputPin2); //the 0-10V input
int potDifference = controlPot-motorPot;
boolean Forward = potDifference >=0;
int motorSpeed = map(abs(potDifference),Deadband,FullSpeedPotDifference,0,MaxSpeed);
motorSpeed = constrain(motorSpeed,0,MaxSpeed); //We need to constrain it to our limits now
//if you're running an H bridge driver, you will have two outputs, one for forward, one for reverse
if (Forward){
analogWrite(ReverseOutputPin,0);//make sure you don't drive in both directions at once!
analogWrite(ForwardOuputPin, motorSpeed);
}
else{
analogWrite(ForwardOutputPin,0);
analogWrite(ReverseOutputPin,motorSpeed);
}
// one way
if (Forward){
if (digitalRead(vent1UPlim)== HIGH) {
analogWrite(vent1PWMB , 0 );
digitalWrite(vent1enable, HIGH);
delay(50);
analogWrite(vent1PWMA ,motorSpeed);
mydisp.drawStr(0, 2, "-close-|");
} else {
analogWrite(vent1PWMA , 0 );
delay(50);
digitalWrite(vent1enable, LOW);
mydisp.drawStr(0, 2, " |");
}
} else {
// other way
if (digitalRead(vent1DOWNlim)== HIGH) {
analogWrite(vent1PWMA , 0 );
digitalWrite(vent1enable, HIGH);
delay(50);
analogWrite(vent1PWMB ,motorSpeed);
mydisp.drawStr(0, 2, "-open -|");
} else {
analogWrite(vent1PWMB , 0 );
delay(50);
digitalWrite(vent1enable, LOW);
mydisp.drawStr(0, 2, " |");
}
}
// disabled drivers when not being used
if (motorSpeed > 100) { // 100 being the min speed?
digitalWrite(vent1enable, LOW);
mydisp.drawStr(0, 2, " |");
zoomkat:
zoomkat:
Code for controlling servos using pots that includes a dead band feature to account for pot noise.
//zoomkat dual pot/servo test 12-29-12
//view output using the serial monitor
#include <Servo.h>
Servo myservoS1;
Servo myservoS2;
int potpinS1 = 0; //analog input pin A0
int potpinS2 = 1;
int newvalS1, oldvalS1;
int newvalS2, oldvalS2;
void setup()
{
Serial.begin(9600);
myservoS1.attach(2);
myservoS2.attach(3);
Serial.println("testing dual pot servo");
}
void loop()
{
newvalS1 = analogRead(potpinS1);
newvalS1 = map(newvalS1, 0, 1023, 0, 179);
if (newvalS1 < (oldvalS1-2) || newvalS1 > (oldvalS1+2)){
myservoS1.write(newvalS1);
Serial.print("1- ");
Serial.println(newvalS1);
oldvalS1=newvalS1;
}
newvalS2 = analogRead(potpinS2);
newvalS2 = map(newvalS2, 0, 1023, 0, 179);
if (newvalS2 < (oldvalS2-2) || newvalS2 > (oldvalS2+2)){
myservoS2.write(newvalS2);
Serial.print("2- ");
Serial.println(newvalS2);
oldvalS2=newvalS2;
}
delay(50); //slow down looping to better read serial monitor
}
this look a easy way to do this but does this still have speed control? and i could add my 0-10v into that was well?
thanks again 