Term 2 Project - Camera drop/retract mechanism code
After doing a little prototyping with polystyrene today to get a better mental image of the ship and where things are going and creating fixtures for the electronics boxes, I have finalised the code for the camera drop mechanism. I still need to code the light sensor/LED combination in, but the code is as below (video below code) :
#define _relay 8
#define _motor 9
const int controlPin1 = 2;
const int controlPin2 = 3;
int previousState;
int motorDirection;
int timex = millis(); //----optional if controlling other things that require it
int timer = 0; //----optional if controlling other things that require it
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
previousState = 1;
motorDirection = 1;
pinMode(_relay, INPUT);
pinMode(_motor, OUTPUT);
pinMode(controlPin1, OUTPUT);
pinMode(controlPin2, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
//--------------------Camera drop in contact with water & retracts when not -------------
//------Water sensor module senses water: drop camera---------------------
if (digitalRead(_relay) == HIGH && previousState ==!1) {
Serial.print(" ON - Submerging Camera ");
digitalWrite(controlPin1, LOW);
digitalWrite(controlPin2, HIGH);
delay(5000);
digitalWrite(_motor, HIGH);
delay(2000);
digitalWrite(_motor, LOW);
previousState = 1;
digitalWrite(controlPin1, LOW);
digitalWrite(controlPin2, LOW);
}
//------Water sensor module does not sense water: retract camera---------------------
if (digitalRead(_relay) == LOW && previousState == 1) {
motorDirection != 1;
Serial.print(" OFF - Retracting Camera");
digitalWrite(controlPin1, HIGH);
digitalWrite(controlPin2, LOW);
delay(5000);
digitalWrite(_motor, HIGH);
delay(2000);
digitalWrite(_motor, LOW);
previousState = !1;
digitalWrite(controlPin1, LOW);
digitalWrite(controlPin2, LOW);
}
}
//---------------------------------------------------------------------------------------------------------------------
Until next time,
Luis
#define _relay 8
#define _motor 9
const int controlPin1 = 2;
const int controlPin2 = 3;
int previousState;
int motorDirection;
int timex = millis(); //----optional if controlling other things that require it
int timer = 0; //----optional if controlling other things that require it
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
previousState = 1;
motorDirection = 1;
pinMode(_relay, INPUT);
pinMode(_motor, OUTPUT);
pinMode(controlPin1, OUTPUT);
pinMode(controlPin2, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
//--------------------Camera drop in contact with water & retracts when not -------------
//------Water sensor module senses water: drop camera---------------------
if (digitalRead(_relay) == HIGH && previousState ==!1) {
Serial.print(" ON - Submerging Camera ");
digitalWrite(controlPin1, LOW);
digitalWrite(controlPin2, HIGH);
delay(5000);
digitalWrite(_motor, HIGH);
delay(2000);
digitalWrite(_motor, LOW);
previousState = 1;
digitalWrite(controlPin1, LOW);
digitalWrite(controlPin2, LOW);
}
//------Water sensor module does not sense water: retract camera---------------------
if (digitalRead(_relay) == LOW && previousState == 1) {
motorDirection != 1;
Serial.print(" OFF - Retracting Camera");
digitalWrite(controlPin1, HIGH);
digitalWrite(controlPin2, LOW);
delay(5000);
digitalWrite(_motor, HIGH);
delay(2000);
digitalWrite(_motor, LOW);
previousState = !1;
digitalWrite(controlPin1, LOW);
digitalWrite(controlPin2, LOW);
}
}
//---------------------------------------------------------------------------------------------------------------------
Until next time,
Luis
Comments
Post a Comment