RCU Forums - View Single Post - converting air to electric retracts.
View Single Post
Old 01-31-2014, 06:22 PM
  #34  
mustang493
Member
 
Join Date: Jan 2013
Location: cambridge, UNITED KINGDOM
Posts: 42
Likes: 0
Received 0 Likes on 0 Posts
Default

Mike you've got loads of syntax errors. you need to verify your code and work through the errors line by line. i've made a start for you..


// Arduino uno with R3 motor shield // RC retract under-carriage sequencing
// door actuators and under-carriage retract actuators


#define midlimit 1700
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
sensorValueA = analogRead(sensorPinA); //this reads the value of current for motorA and sets the variable sensorValueA , doors
sensorValueB = analogRead(sensorPinB); //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==1 && sensorValueB < limitB && iB==0)
if (updwn==updwn2 && sensorValueA < 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);
}
}