RE: converting air to electric retracts.
This is the code you'll need to program your Arduino UNO. If you're familiar with code you'll get the idea. if not i'll explain in later posts<div>cut and paste from #include<Servo.h......</div><div>
</div><div><div>
</div><div>
</div><div>#include <Servo.h> //needed to operate the servos</div><div>#define midlimit 1700</div><div>Servo myservoA;</div><div>Servo myservoB;</div><div>
</div><div>int Bbrake=8;//brake signal for motor B</div><div>int Abrake=9;//brake signal for motor A</div><div>int motorspdB=11;//PWM speed signal for motor B</div><div>int motorspdA=3;//PWM speed signal for motor A</div><div>int ch5;</div><div>int motorA=12;</div><div>int motorB=13;</div><div>int sensorPinA = A0; // select the input pin for the current</div><div>int sensorPinB = A1; // select the input pin for the current</div><div>int switchpin = 2;</div><div>int sensorValueA = 0; // variable to store the value coming from the sensor</div><div>int sensorValueB = 0; // variable to store the value coming from the sensor</div><div>
</div><div>void setup () {</div><div>
</div><div> pinMode (6, INPUT);</div><div> pinMode (13, OUTPUT);//motor B enable and direction HIGH or LOW</div><div> pinMode (12, OUTPUT);//motor A enable and direction HIGH or LOW</div><div> pinMode (8, OUTPUT);//Brake motor B</div><div> pinMode (9, OUTPUT);//Brake motor A</div><div> pinMode (4, OUTPUT);//servo A pin</div><div> pinMode (7, OUTPUT);//servo B pin </div><div> pinMode (switchpin, OUTPUT);</div><div> myservoA.attach(4);</div><div> myservoB.attach(7);</div><div>}</div><div>void loop () {</div><div>
</div><div> int limitA = 550; //this is the current limit for motor A</div><div> int limitB = 300; //this is the current limit for motor B</div><div> sensorValueB = analogRead(sensorPinB); //this reads the value of current for motorB and sets the variable sensorValueB</div><div> sensorValueA = analogRead(sensorPinA); //this reads the value of current for motorA and sets the variable sensorValueA</div><div> int iB = 0; //this creates and sets a variable named iB which we will use to make sure the motors stop once they reach overcurrent condition</div><div> int iA = 0; //this creates and sets a variable named iA which we will use to make sure the motors stop once they reach overcurrent condition</div><div> myservoA.writeMicroseconds(900);</div><div> myservoB.writeMicroseconds(900);</div><div> ch5 = pulseIn(6, HIGH);</div><div>
</div><div> if (ch5 < midlimit) {</div><div> digitalWrite(switchpin, HIGH);</div><div> }</div><div> else {</div><div> digitalWrite(switchpin, LOW);</div><div> }</div><div> int updwn = digitalRead(switchpin); //this sets the value of the variable updwn which is read from transmitter switch</div><div> int updwn2 = digitalRead(switchpin); //this sets the comparison value of updwn which is read from transmitter switch</div><div>
</div><div> while (updwn == updwn2) { //the while loop here knows the current state of the switch updwn. during the while loop it will continually check </div><div> //the state of the switch by setting updwn2 therefore once the state of the switch changes it will exit the while loop</div><div>
</div><div> if (updwn==1 && sensorValueB < limitB && iB==0) </div><div> {</div><div> analogWrite (motorspdB,255);</div><div> digitalWrite (motorB,HIGH);</div><div> digitalWrite (Bbrake,LOW);</div><div> }</div><div> else if (updwn==0 && sensorValueB < limitB && iB==0) </div><div> {</div><div> analogWrite (motorspdB,255);</div><div> digitalWrite (motorB,LOW);</div><div> digitalWrite (Bbrake,LOW);</div><div> }</div><div> else </div><div> {</div><div> analogWrite (motorspdB,0);</div><div> digitalWrite (Bbrake,LOW);</div><div> myservoB.writeMicroseconds(2095);</div><div> iB++;</div><div> }</div><div> delay(300);</div><div> if (updwn==1 && sensorValueA < limitA && iA==0)</div><div> {</div><div> analogWrite (motorspdA,255);</div><div> digitalWrite (motorA,HIGH);</div><div> digitalWrite (Abrake,LOW);</div><div> }</div><div> else if (updwn==0 && sensorValueA < limitA && iA==0) </div><div> {</div><div> analogWrite (motorspdA,255);</div><div> digitalWrite (motorA,LOW);</div><div> digitalWrite (Abrake,LOW);</div><div> }</div><div> else</div><div> {</div><div> analogWrite (motorspdA,0);</div><div> digitalWrite (Abrake,LOW);</div><div> myservoA.writeMicroseconds(2125);</div><div> iA++;</div><div> } </div><div> delay(200);</div><div>
</div><div> sensorValueB = analogRead(sensorPinB);</div><div> sensorValueA = analogRead(sensorPinA);</div><div>
</div><div> int ch5 = pulseIn(6, HIGH);</div><div> if (ch5 < midlimit) </div><div> {</div><div> digitalWrite(switchpin, HIGH);</div><div> }</div><div> else </div><div> {</div><div> digitalWrite(switchpin, LOW);</div><div> }</div><div> updwn2 = digitalRead(switchpin);</div><div> delay(100);</div><div>
</div><div> }</div><div>}</div><div>
</div><div>
</div></div>