RCU Forums - View Single Post - converting air to electric retracts.
View Single Post
Old 01-23-2014 | 02:45 PM
  #30  
freelander-rider
Junior Member
 
Joined: Jan 2014
Posts: 10
Likes: 0
Received 0 Likes on 0 Posts
From: Grantham
Default

Mustang,
This is the edited code:-
// Arduino uno with R3 motor shield // RC retract under-carriage sequencing
// door actuators and under-carriage retract actuators


int Abrake=8; // brake signal for motor A doors actuators
int Bbrake=9; // brake signal for motor B retract actuators
int motorspdA=11; // PWM speed signal for motor A doors actuator
int motorspdB=3; // PWM speed signal for motor B retract actuators
int ch5; // Receiver retract channel
int motorA=12; // motor initiate door actuators
int motorB=13; // motor initiate retract actuators
int sensorPinA= A0; // select the input pin for the current door actuators
int sensorPinB= A1; // select the input pin for the current retract actuators
int switchpin =2;
int sensorValueA =0; // variable to store the value coming from the sensor
int sensorValueB =0; // variable to store the value coming from the sensor


void setup() {


pinMode (6, INPUT);
pinMode (12,OUTPUT); // motor A enable and direction HIGH or LOW
pinMode (13,OUTPUT); // motor B enable and direction HIGH or LOW
pinMode (8, OUTPUT); // brake motor A doors
pinMode (9, OUTPUT); // brake motor B retracts
pinMode (switchpin, OUTPUT);

}
void Ioop () {


int limitA = 550; // this is the current limit for motor A doors
Int limitB = 300; // this is the current limit for motor B retracts
sensor ValueA = analogRead(sensorPinA); //this reads the value of current for motorA and sets the variable sensorValueA , doors
sensorValueB = analogRead(senserPinB); //this reads the value of current for motorB and sets the variable sensor valueB , retracts
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
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
ch5 = pulseIn(6, HIGH);
If(ch5 < midlimit) {
digitalWrite(switchpin, HIGH);
}
else {
digitalWrite(switchpin, LOW);
}
int updwn = digitalRead(switchpin); // this sets the value of the variable updwn which is read from transmitter switch
int updwn2 = digitalRead(switchpin); // this sets the value of the variable updwn which is read from transmitter switch
while (updwn = = updwn2 { // the while loop here knows the current state of the switch updwn. During the while loop it will continually check
//the state of the switch by setting updwn2 therefore once the state of the switch changes it will exit the while loop


if (updwn = = updwn 1 && senserValueA < limitA && iA = =0)
{
analogWrite (motorspdA,255);
digitalWrite (A,HIGH);
digitalWrite(Brake,LOW);
}
else if (updwn = =0 && sensorValueA < limit A && iA = =iA = =0)
{
analogWrite (motorspdA,255);
digital Write (motorA,LOW);
Digital Write (Brake,LOW);
}
else
{
analogWrite ( motorspdA ,0);
digitalWrite (Brake,LOW);
iA++;
}
delay(300);
if (updwn = =1 && sensorValueB < limitB&& iB = =0)
{
analogWrite (motorspdB,255);
digital Write (motorB,HIGH);
digital Write (Bbrake,LOW);
}
else if (updwn = =0 && sensorValueB < limitB && iB = =0)
{
analogWrite (motorspdB,255);
digitalWrite (motorB,LOW);
digitalWrite (Bbrake.LOW);
}
else
{
analogWrite (motorspdB,0);
digitalWrite (Bbrake,LOW);
iB++;
}
delay(200);
sensorValueA = analogRead(sensorPinA);
sensorValueB =analogRead(sensorPinB);
int ch5 = pulseIn(6,HIGH);
If (ch5 < midlimit)
{
digitalWrite(switchpin,HIGH);
}
else
{
digitalWrite(switchpin, LOW);
}
Updwn2 = digitalRead(switchpin);
delay(100);
}
}

basically I have re-arranged the outputs on A and B, and omitted the servo commands, but I may have made mistakes doing this I'm not really sure.
Mike

Last edited by freelander-rider; 01-30-2014 at 12:12 PM. Reason: CORRECTING ERRORS