Hi,
I am building a sketch to control the radar dish on a display aircraft. The dish is located in a housing that either raises the dish into the fuselage or lowers to working height. I have a manual control box that will control motors and direction but also want to use an automated sketch that will lower, rotate dish for a period of time, raise and repeat after a period of time. There is a switch on the manual control box for manual and auto. Question is how to I split the sketch so that on power on it does whatever the manual / auto switch reads. I have been looking at sub loops based on switchstate of manual / auto switch. Could someone point me in the right direction.
Fairey Gannet Radar Control
Two motors.
Motor 1 12v Controls the rotation of the radar dish. Normal two wire motor.
Motor 2 28v controls the raise / lower of the radar dish mechanism. Two poistive wires, one for up and one for down, single negative.
Two limit switches. Limit switch Up, upper travel of radar dish mechanism. Limit switch Dwn, lower travel of radar dish mechanism.
Caution: The radar dish will hit the ground on full travel. Travel to be restricted with lower travel limit switch.
Two circuits.
1. Auto. From any position.
Lowers mechanism until lower limit switch activated.
Rotate the radar dish for xxx milliseconds.
Raise mechanism until upper limit switch activated.
Hold in upper position for xxx milliseconds, then repeat.
2. Manual. From any position.
Rocker switch on hand control box to activate manual or automatic mode.
Note. Raise and lower motor to be controlled at end stops by limit swicthes to prevent damage.
Circuit selection from rocket switch high for auto and low for manual. To be selected before power up.
Dish rotate motor and Arduino power supply from 12v dc, raise and lower motor power requirements from seperate transformer.
*/
// constants used to set pin numbers:
const int upperLimit = 3; // upper limit switch assigned to pin 3, switch to ground pull up
const int lowerLimit = 4; // lower limit switch assigned to pin 4, switch to ground pull up
const int modeSelect = 7; // manual or auto mode rocker switch assigned to pin 7, switch to ground pull up
const int motorDishenR = 15; // dish rotate motor rotate cw enable pin 3. digital output
const int motorDishenL = 2; // dish rotate motor rotate ccw enable pin 5. digital output
const int motorDishR = 9; // dish rotate motor speed control. PWM output pin 9
const int motorDishL = 10; // dish rotate motor speed control. PWM output pin 10
const int motorMechU = 5; // dish mechanism raise. 3v Signal to SSR DC at pin 5
const int motorMechL = 6; // dih mechanism lower. 3v Signla to SSR Dc at pin 6
const int uP = 7; // manual button up
const int lwR = 11; // manual button down
const int cW = 12; // manual button clockwise
const int ccW = 13; // manual button counter-clockwise
// variables will change:
int bsupplimit = 0; // button state for upper limit switch
int bslowlimit = 1; // button state for lower limit switch
int bsmodeselect = 0; // button state for mode select switch
void setup() {
// initialize following pins as input:
pinMode(upperLimit, INPUT_PULLUP);
pinMode(lowerLimit, INPUT_PULLUP);
pinMode(modeSelect, INPUT_PULLUP);
pinMode(uP, INPUT_PULLUP);
pinMode(lwR, INPUT_PULLUP);
pinMode(cW, INPUT_PULLUP);
pinMode(ccW, INPUT_PULLUP);
// initialize following pins as an output:
pinMode(motorDishenR, OUTPUT);
pinMode(motorDishenL, OUTPUT);
pinMode(motorDishR, OUTPUT);
pinMode(motorDishL, OUTPUT);
pinMode(motorMechU, OUTPUT);
pinMode(motorMechL, OUTPUT);
}
void loop() { //The following to run if modeSelect button is high
int buttonState1 = digitalRead(uP);
int buttonState2 = digitalRead(lwR);
int buttonState3 = digitalRead(cW);
int buttonState4 = digitalRead(ccW);
int buttonState5 = digitalRead(upperLimit);
int buttonState6 = digitalRead(lowerLimit);
int buttonState7 = digitalRead(modeSelect);
if (buttonState1 == HIGH and buttonState2 == LOW and buttonState3 == LOW and buttonState4 == LOW and buttonState5 == LOW and buttonState6 == LOW) {
digitalWrite(motorMechU, HIGH);
} else {
digitalWrite(motorMechU, LOW); {
}
}
if (buttonState2 == HIGH and buttonState1 == LOW and buttonState3 == LOW and buttonState4 == LOW and buttonState5 == LOW and buttonState6 == LOW) {
digitalWrite(motorMechL, HIGH);
} else {
digitalWrite(motorMechL, LOW); {
}
}
if (buttonState3 == HIGH and buttonState1 == LOW and buttonState2 == LOW and buttonState4 == LOW and buttonState5 == LOW and buttonState6 == LOW) {
digitalWrite(motorDishenR, HIGH);
analogWrite(motorDishR, 200); //speed to be set on build
} else {
digitalWrite(motorDishenR, LOW); {
}
}
if (buttonState4 == HIGH and buttonState1 == LOW and buttonState2 == LOW and buttonState3 == LOW and buttonState5 == LOW and buttonState6 == LOW) {
digitalWrite(motorDishenL, HIGH);
analogWrite(motorDishL, 200); //speed to be set on build
} else {
digitalWrite(motorDishenL, LOW); {
}
}
if (buttonState5 == HIGH) {
digitalWrite(motorMechU, LOW);
}
if (buttonState6 == HIGH) {
digitalWrite(motorMechL, LOW);
}
// The following to run if modeSelect button is low
//int buttonState1 = digitalRead(uP);
//int buttonState2 = digitalRead(lwR);
if (buttonState1 == HIGH); {
digitalWrite(motorMechU, LOW);
}
if (buttonState2 == HIGH);{
digitalWrite(motorMechL, LOW);
}
digitalWrite(motorMechL, HIGH);
digitalWrite(motorDishenR, HIGH);
analogWrite(motorDishR, 200); //speed to be set on build
//dwell with Millis here while dish rotates
digitalWrite(motorDishenR, LOW);
digitalWrite(motorMechU, HIGH);
//dwell with Millis here for a period before dish goes down, reads from line 129
}