/* SUbmarine Simulator */
/* John Hatfield */
/* 12/17/2022 */
/* Submarine Simulator V1 control surfaces */
/* 3 servos 3 potentiometers for control */
/* servo1 = rudder
servo2 = hydroplane
servo3 = balast tank */
/* Ultra Distance = Sensor Sonar */
/* Stepper Motor = Propeller
/* OLED */
/* Operation Dry Run - rudder and dive planes */
/* Stepper motor added
/*Librarys*/
#include <Servo.h>
#include <Stepper.h>
Servo rudder; // create servo object to control RUDDER
Servo hydro; // create servo object to control HYDROPLANE
Servo balast; // create servo object to control BALAST TANKS
int rudderpotpin = 0; // analog pin used to connect the potentiometer
int val1; // variable to read the value from the analog pin
int hydropotpin = 1; // analog pin used to connect the potentiometer
int val2; // variable to read the value from the analog pin
int balastpotpin = 2; // analog pin used to connect the potentiometer
int val3; // variable to read the value from the analog pin
void setup() {
rudder.attach(9); // attaches the servo RUDDER on pin 9 to the servo object
hydro.attach(8); // attaches the servo hydro on pin 8
balast.attach(7); // attaches the servo balast on pin 7
}
void loop() {
val1 = analogRead(rudderpotpin); // reads the value of the potentiometer (value between 0 and 1023)
val1 = map(val1, 0, 1023, 0, 180); // scale it to use it with the servo (value between 0 and 180)
rudder.write(val1); // sets the servo position according to the scaled value
delay(15); // waits for the servo to get there
val2 = analogRead(hydropotpin);
val2 = map(val2, 0, 1023, 0, 180);
hydro.write(val2);
delay(20);
val3 = analogRead(balastpotpin);
val3 = map(val3, 0,1023,0,180);
balast.write(val3);
delay(15);
}