#include "U8glib.h" // U8glib library for the OLED
#include <LiquidCrystal_I2C.h>
#include <Wire.h>
#include <EEPROM.h>
#include <ezButton.h>
void(* resetFunc) (void) = 0;
U8GLIB_SH1106_128X64 u8g(U8G_I2C_OPT_DEV_0 | U8G_I2C_OPT_FAST);
LiquidCrystal_I2C lcd(0x27, 20, 4);
// main station sensors
#define sensorPin A0 //feedback left nozzle steering potentiometer
#define sensorPin1 A1 //feedback left deflector potentiometer
#define sensorPin2 A2 //feedback right nozzle potentiometer
#define sensorPin3 A3 //feedback right deflector potentiometer
#define sensorPin4 A4 // input steering control lever
#define sensorPin5 A5 // input left deflector control
#define sensorPin6 A6 //input right deflector control
// station 1
#define sensorPin7 A7 // input steering control lever
#define sensorPin8 A8 // input left deflector control
#define sensorPin9 A9 //input right deflector control
// station 2
#define sensorPin10 A10 // input steering control lever
#define sensorPin11 A11 // input left deflector control
#define sensorPin12 A12 //input right deflector control
// station 3
#define sensorPin13 A13 // input steering control lever
#define sensorPin14 A14 // input left deflector control
#define sensorPin15 A15 //input right deflector control
// led connections
#define led1 2
#define led2 3
#define led3 4
#define led4 5
// flags for each station
bool flag_1 = 0;
bool flag_2 = 0;
bool flag_3 = 0;
bool flag_m = 0;
bool flag_centers = 0;
bool flag_erase = 0;
// switch connections
ezButton button(10);
#define switch2 11
#define switch3 12
#define switch4 13
#define switch5 9
#define switch6 8
bool buttonstate1;
int buttonReading2;
int state2 = LOW;
int previous2 = LOW;
// station1 values/////////
int buttonReading3;
int state3 = LOW;
int previous3 = LOW;
float sensorValue7 = 0;
int sensorMin7 = 1023;
int sensorMax7 = 0;
int intValue7;
float sensorValue8 = 0;
int sensorMin8 = 1023;
int sensorMax8 = 0;
int intValue8;
float sensorValue9 = 0;
int sensorMin9 = 1023;
int sensorMax9 = 0;
int intValue9;
int center7 = 0;
int left7 = 0;
int right7 = 0;
int center8 = 0;
int left8 = 0;
int right8 = 0;
int center9 = 0;
int left9 = 0;
int right9 = 0;
int Center7 = 0 ;
int Left7 = 0;
int Right7 = 0;
int Center8 = 0;
int Left8 = 0 ;
int Right8 = 0 ;
int Center9 = 0;
int Left9 = 0 ;
int Right9 = 0 ;
/////////////////////
// station2 values/////////
int buttonReading4;
int state4 = LOW;
int previous4 = LOW;
float sensorValue10 = 0;
int sensorMin10 = 1023;
int sensorMax10 = 0;
int intValue10;
float sensorValue11 = 0;
int sensorMin11 = 1023;
int sensorMax11 = 0;
int intValue11;
float sensorValue12 = 0;
int sensorMin12 = 1023;
int sensorMax12 = 0;
int intValue12;
int center10 = 0;
int left10 = 0;
int right10 = 0;
int center11 = 0;
int left11 = 0;
int right11 = 0;
int center12 = 0;
int left12 = 0;
int right12 = 0;
int Center10 = 0 ;
int Left10 = 0;
int Right10 = 0;
int Center11 = 0;
int Left11 = 0 ;
int Right11 = 0 ;
int Center12 = 0;
int Left12 = 0 ;
int Right12 = 0 ;
////////////////////
// station3 values/////////
int buttonReading5;
int state5 = LOW;
int previous5 = LOW;
float sensorValue13 = 0;
int sensorMin13 = 1023;
int sensorMax13 = 0;
int intValue13;
float sensorValue14 = 0;
int sensorMin14 = 1023;
int sensorMax14 = 0;
int intValue14;
float sensorValue15 = 0;
int sensorMin15 = 1023;
int sensorMax15 = 0;
int intValue15;
int center13 = 0;
int left13 = 0;
int right13 = 0;
int center14 = 0;
int left14 = 0;
int right14 = 0;
int center15 = 0;
int left15 = 0;
int right15 = 0;
int Center13 = 0 ;
int Left13 = 0;
int Right13 = 0;
int Center14 = 0;
int Left14 = 0 ;
int Right14 = 0 ;
int Center15 = 0;
int Left15 = 0 ;
int Right15 = 0 ;
/////////////////////
// Main station sensors variables
int buttonReading6;
int state6 = LOW;
int previous6 = LOW;
float sensorValue = 0;
int sensorMin = 1023;
int sensorMax = 0;
int intValue;
float sensorValue1 = 0;
int sensorMin1 = 1023;
int sensorMax1 = 0;
int intValue1;
float sensorValue2 = 0;
int sensorMin2 = 1023;
int sensorMax2 = 0;
int intValue2;
float sensorValue3 = 0;
int sensorMin3 = 1023;
int sensorMax3 = 0;
int intValue3;
float sensorValue4 = 0;
int sensorMin4 = 1023;
int sensorMax4 = 0;
int intValue4;
float sensorValue5 = 0;
int sensorMin5 = 1023;
int sensorMax5 = 0;
int intValue5;
float sensorValue6 = 0;
int sensorMin6 = 1023;
int sensorMax6 = 0;
int intValue6;
int center = 0;
int left = 0;
int right = 0;
int center1 = 0;
int left1 = 0;
int right1 = 0;
int center2 = 0;
int left2 = 0;
int right2 = 0;
int center3 = 0;
int left3 = 0;
int right3 = 0;
int center4 = 0;
int left4 = 0;
int right4 = 0;
int center5 = 0;
int left5 = 0;
int right5 = 0;
int center6 = 0;
int left6 = 0;
int right6 = 0;
int Center = 0 ;
int Left = 0;
int Right = 0;
int Center1 = 0;
int Left1 = 0 ;
int Right1 = 0 ;
int Center2 = 0;
int Left2 = 0 ;
int Right2 = 0 ;
int Center3 = 0;
int Left3 = 0 ;
int Right3 = 0 ;
int Center4 = 0;
int Left4 = 0 ;
int Right4 = 0 ;
int Center5 = 0;
int Left5 = 0 ;
int Right5 = 0 ;
int Center6 = 0;
int Left6 = 0 ;
int Right6 = 0 ;
unsigned long num = 0;
int num1 = 0;
int num2 = 0;
int num3 = 0;
int threshold = 10;
// main station
// port
#define switch7 22
#define switch8 23
#define switch9 24
ezButton button1(switch7);
ezButton button2(switch8);
ezButton button3(switch9);
// stbd
#define switch10 25
#define switch11 26
#define switch12 27
ezButton button4(switch10);
ezButton button5(switch11);
ezButton button6(switch12);
// relays
#define led5 50
#define led6 51
#define led7 52
#define led8 53
//flags
bool flag_1_p = 0;
bool flag_3_p = 0;
bool flag_1_s = 0;
bool flag_3_s = 0;
// rams
// port
#define left_ram_p 28
#define right_ram_p 29
#define up_ram_p 30
#define down_ram_p 31
// stbd
#define left_ram_s 32
#define right_ram_s 33
#define up_ram_s 34
#define down_ram_s 35
void setup()
{
lcd.init();
lcd.backlight();
lcd.begin (20, 4);
pinMode (left_ram_p, OUTPUT);
pinMode (right_ram_p, OUTPUT);
pinMode (up_ram_p, OUTPUT);
pinMode (down_ram_p, OUTPUT);
pinMode (left_ram_s, OUTPUT);
pinMode (right_ram_s, OUTPUT);
pinMode (up_ram_s, OUTPUT);
pinMode (down_ram_s, OUTPUT);
digitalWrite(left_ram_p,HIGH);
digitalWrite(right_ram_p,HIGH);
digitalWrite(up_ram_p,HIGH);
digitalWrite(down_ram_p,HIGH);
digitalWrite(left_ram_s,HIGH);
digitalWrite(right_ram_s,HIGH);
digitalWrite(up_ram_s,HIGH);
digitalWrite(down_ram_s,HIGH);
Serial.begin (9600);
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
pinMode(led4, OUTPUT);
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
digitalWrite(led4, LOW);
pinMode(switch2, INPUT_PULLUP);
pinMode(switch3, INPUT_PULLUP);
pinMode(switch4, INPUT_PULLUP);
pinMode(switch5, INPUT_PULLUP);
pinMode(switch6, INPUT_PULLUP);
button.setDebounceTime(50); // set debounce time to 100 milliseconds
button.setCountMode(COUNT_RISING);
Serial.begin(9600);
button1.setDebounceTime(50);
button2.setDebounceTime(50);
button3.setDebounceTime(50);
button4.setDebounceTime(50);
button5.setDebounceTime(50);
button6.setDebounceTime(50);
pinMode (led5, OUTPUT);
pinMode (led6, OUTPUT);
pinMode (led7, OUTPUT);
pinMode (led8, OUTPUT);
lcd.setCursor (6, 0);
lcd.print ("Please");
lcd.setCursor (6, 1);
lcd.print ("Select");
lcd.setCursor (7, 2);
lcd.print ("Station");
loadeprom();
u8g.setColorIndex(1);
}
void eraseeeprom()
{
EEPROM.put(0, 0);
delay(10);
EEPROM.put(10, 0);
delay(10);
EEPROM.put(20, 0);
delay(10);
EEPROM.put(30, 0);
delay(10);
EEPROM.put(40, 0);
delay(10);
EEPROM.put(50, 0);
delay(10);
EEPROM.put(60, 0);
delay(10);
EEPROM.put(70, 0);
delay(10);
EEPROM.put(80, 0);
delay(10);
EEPROM.put(90, 0);
delay(10);
EEPROM.put(100, 0);
delay(10);
EEPROM.put(110, 0);
delay(10);
EEPROM.put(120, 0);
delay(10);
EEPROM.put(130, 0);
delay(10);
EEPROM.put(140, 0);
delay(10);
EEPROM.put(150, 0);
delay(10);
EEPROM.put(160, 0);
delay(10);
EEPROM.put(170, 0);
delay(10);
EEPROM.put(180, 0);
delay(10);
EEPROM.put(190, 0);
delay(10);
EEPROM.put(200, 0);
delay(10);
EEPROM.put(210, 0);
delay(10);
EEPROM.put(220, 0);
delay(10);
EEPROM.put(230, 0);
delay(10);
EEPROM.put(240, 0);
delay(10);
EEPROM.put(250, 0);
delay(10);
EEPROM.put(260, 0);
delay(10);
EEPROM.put(270, 0);
delay(10);
EEPROM.put(280, 0);
delay(10);
EEPROM.put(290, 0);
delay(10);
EEPROM.put(300, 0);
delay(10);
EEPROM.put(310, 0);
delay(10);
EEPROM.put(320, 0);
delay(10);
EEPROM.put(330, 0);
delay(10);
EEPROM.put(340, 0);
delay(10);
EEPROM.put(350, 0);
delay(10);
EEPROM.put(360, 0);
delay(10);
EEPROM.put(370, 0);
delay(10);
EEPROM.put(380, 0);
delay(10);
EEPROM.put(390, 0);
delay(10);
EEPROM.put(400, 0);
delay(10);
EEPROM.put(410, 0);
delay(10);
EEPROM.put(420, 0);
delay(10);
EEPROM.put(430, 0);
delay(10);
EEPROM.put(440, 0);
delay(10);
EEPROM.put(450, 0);
delay(10);
EEPROM.put(460, 0);
delay(10);
EEPROM.put(470, 0);
delay(10);
}
void callibSCP()
{
delay(100);
lcd.clear();
lcd.setCursor (2, 0);
lcd.print ("Calibration mode");
lcd.setCursor (3, 1);
lcd.print ("Sreering cont");
lcd.setCursor (7, 2);
lcd.print ("Move");
lcd.setCursor (4, 3);
lcd.print ("Port to Stbd");
sensorValue = analogRead(sensorPin);
if (sensorValue > sensorMax)
{
sensorMax = sensorValue;
}
if (sensorValue < sensorMin)
{
sensorMin = sensorValue;
}
left = center - sensorMin;
right = sensorMax - center;
Serial.print("Center :");
Serial.print(center);
Serial.print("Left :");
Serial.print(left);
Serial.print("Right :");
Serial.print(right);
Serial.println("");
EEPROM.put(0, center);
delay(10);
EEPROM.put(10, left);
delay(10);
EEPROM.put(20, right);
delay(10);
}
void g_mainstation()
{
button1.loop();
button2.loop();
button3.loop();
button4.loop();
button5.loop();
button6.loop();
if (button1.isPressed())
{
if (flag_1_p == 0)
{
digitalWrite(led5, HIGH);
digitalWrite(led6, LOW);
flag_3_p = 1;
}
}
if (button2.isPressed())
{
flag_1_p = 0;
flag_3_p = 0;
digitalWrite(led5, LOW);
digitalWrite(led6, LOW);
}
if (button3.isPressed() )
{
if (flag_3_p == 0)
{
digitalWrite(led5, LOW);
digitalWrite(led6, HIGH);
flag_1_p = 1;
}
}
if (button4.isPressed())
{
if (flag_1_s == 0)
{
digitalWrite(led7, HIGH);
digitalWrite(led8, LOW);
flag_3_s = 1;
}
}
if (button5.isPressed())
{
flag_1_s = 0;
flag_3_s = 0;
digitalWrite(led7, LOW);
digitalWrite(led8, LOW);
}
if (button6.isPressed() )
{
if (flag_3_s == 0)
{
digitalWrite(led7, LOW);
digitalWrite(led8, HIGH);
flag_1_s = 1;
}
}
}
void callibPDC()
{
delay(100);
lcd.clear();
lcd.setCursor (2, 0);
lcd.print ("Calibration mode");
lcd.setCursor (0, 1);
lcd.print ("Port deflector cont");
lcd.setCursor (7, 2);
lcd.print ("Move"); //and another load of these from A0 to A10
lcd.setCursor (3, 3);
lcd.print ("Ahead to Astern");
sensorValue1 = analogRead(sensorPin1);
if (sensorValue1 > sensorMax1)
{
sensorMax1 = sensorValue1;
}
if (sensorValue1 < sensorMin1)
{
sensorMin1 = sensorValue1;
}
left1 = center1 - sensorMin1;
right1 = sensorMax1 - center1;
Serial.print("Center :");
Serial.print(center1);
Serial.print("Left :");
Serial.print(left1);
Serial.print("Right :");
Serial.print(right1);
Serial.println("");
EEPROM.put(30, center1);
delay(10);
EEPROM.put(40, left1);
delay(10);
EEPROM.put(50, right1);
delay(10);
}
void callibstbd()
{
delay(100);
lcd.clear();
lcd.setCursor (2, 0);
lcd.print ("Calibration mode");
lcd.setCursor (0, 1);
lcd.print ("stbd deflector cont");
lcd.setCursor (7, 2);
lcd.print ("Move"); //and another load of these from A0 to A10
lcd.setCursor (3, 3);
lcd.print ("Ahead to Astern");
sensorValue2 = analogRead(sensorPin2);
if (sensorValue2 > sensorMax2)
{
sensorMax2 = sensorValue2;
}
if (sensorValue2 < sensorMin2)
{
sensorMin2 = sensorValue2;
}
left2 = center2 - sensorMin2;
right2 = sensorMax2 - center2;
Serial.print("Center :");
Serial.print(center2);
Serial.print("Left :");
Serial.print(left2);
Serial.print("Right :");
Serial.print(right2);
Serial.println("");
EEPROM.put(60, center2);
delay(10);
EEPROM.put(70, left2);
delay(10);
EEPROM.put(80, right2);
delay(10);
}
// Station 1
void callibSCP1()
{
delay(100);
lcd.clear();
lcd.setCursor (2, 0);
lcd.print ("Calib Station 1");
lcd.setCursor (3, 1);
lcd.print ("Sreering cont");
lcd.setCursor (7, 2);
lcd.print ("Move"); //and another load of these from A0 to A10
lcd.setCursor (4, 3);
lcd.print ("Port to Stbd");
sensorValue7 = analogRead(sensorPin7);
if (sensorValue7 > sensorMax7)
{
sensorMax7 = sensorValue7;
}
if (sensorValue7 < sensorMin7)
{
sensorMin7 = sensorValue7;
}
left7 = center7 - sensorMin7;
right7 = sensorMax7 - center7;
Serial.print("Center :");
Serial.print(center7);
Serial.print("Left :");
Serial.print(left7);
Serial.print("Right :");
Serial.print(right7);
Serial.println("");
EEPROM.put(210, center7);
delay(10);
EEPROM.put(220, left7);
delay(10);
EEPROM.put(230, right7);
delay(10);
}
void callibPDC1()
{
delay(100);
lcd.clear();
lcd.setCursor (2, 0);
lcd.print ("Calib Station 1");
lcd.setCursor (0, 1);
lcd.print ("Port deflector cont");
lcd.setCursor (7, 2);
lcd.print ("Move"); //and another load of these from A0 to A10
lcd.setCursor (3, 3);
lcd.print ("Ahead to Astern");
sensorValue8 = analogRead(sensorPin8);
if (sensorValue8 > sensorMax8)
{
sensorMax8 = sensorValue8;
}
if (sensorValue8 < sensorMin8)
{
sensorMin8 = sensorValue8;
}
left8 = center8 - sensorMin8;
right8 = sensorMax8 - center8;
Serial.print("Center :");
Serial.print(center8);
Serial.print("Left :");
Serial.print(left8);
Serial.print("Right :");
Serial.print(right8);
Serial.println("");
EEPROM.put(240, center8);
delay(10);
EEPROM.put(250, left8);
delay(10);
EEPROM.put(260, right8);
delay(10);
}
void callibstbd1()
{
delay(100);
lcd.clear();
lcd.setCursor (2, 0);
lcd.print ("Calib Station 1");
lcd.setCursor (0, 1);
lcd.print ("stbd deflector cont");
lcd.setCursor (7, 2);
lcd.print ("Move"); //and another load of these from A0 to A10
lcd.setCursor (3, 3);
lcd.print ("Ahead to Astern");
sensorValue9 = analogRead(sensorPin9);
if (sensorValue9 > sensorMax9)
{
sensorMax9 = sensorValue9;
}
if (sensorValue9 < sensorMin9)
{
sensorMin9 = sensorValue9;
}
left9 = center9 - sensorMin9;
right9 = sensorMax9 - center9;
Serial.print("Center :");
Serial.print(center9);
Serial.print("Left :");
Serial.print(left9);
Serial.print("Right :");
Serial.print(right9);
Serial.println("");
EEPROM.put(270, center9);
delay(10);
EEPROM.put(280, left9);
delay(10);
EEPROM.put(290, right9);
delay(10);
}
// station 2 callib
void callibSCP2()
{
delay(100);
lcd.clear();
lcd.setCursor (2, 0);
lcd.print ("Calib Station 2");
lcd.setCursor (3, 1);
lcd.print ("Sreering cont");
lcd.setCursor (7, 2);
lcd.print ("Move"); //and another load of these from A0 to A10
lcd.setCursor (4, 3);
lcd.print ("Port to Stbd");
sensorValue10 = analogRead(sensorPin10);
if (sensorValue10 > sensorMax10)
{
sensorMax10 = sensorValue10;
}
if (sensorValue10 < sensorMin10)
{
sensorMin10 = sensorValue10;
}
left10 = center10 - sensorMin10;
right10 = sensorMax10 - center10;
Serial.print("Center :");
Serial.print(center10);
Serial.print("Left :");
Serial.print(left10);
Serial.print("Right :");
Serial.print(right10);
Serial.println("");
EEPROM.put(300, center10);
delay(10);
EEPROM.put(310, left10);
delay(10);
EEPROM.put(320, right10);
delay(10);
}
void callibPDC2()
{
delay(100);
lcd.clear();
lcd.setCursor (2, 0);
lcd.print ("Calib Station 2");
lcd.setCursor (0, 1);
lcd.print ("Port deflector cont");
lcd.setCursor (7, 2);
lcd.print ("Move"); //and another load of these from A0 to A10
lcd.setCursor (3, 3);
lcd.print ("Ahead to Astern");
sensorValue11 = analogRead(sensorPin11);
if (sensorValue11 > sensorMax11)
{
sensorMax11 = sensorValue11;
}
if (sensorValue11 < sensorMin11)
{
sensorMin11 = sensorValue11;
}
left11 = center11 - sensorMin11;
right11 = sensorMax11 - center11;
Serial.print("Center :");
Serial.print(center11);
Serial.print("Left :");
Serial.print(left11);
Serial.print("Right :");
Serial.print(right11);
Serial.println("");
EEPROM.put(330, center11);
delay(10);
EEPROM.put(340, left11);
delay(10);
EEPROM.put(350, right11);
delay(10);
}
void callibstbd2()
{
delay(100);
lcd.clear();
lcd.setCursor (2, 0);
lcd.print ("Calib Station 2");
lcd.setCursor (0, 1);
lcd.print ("stbd deflector cont");
lcd.setCursor (7, 2);
lcd.print ("Move"); //and another load of these from A0 to A10
lcd.setCursor (3, 3);
lcd.print ("Ahead to Astern");
sensorValue12 = analogRead(sensorPin12);
if (sensorValue12 > sensorMax12)
{
sensorMax12 = sensorValue12;
}
if (sensorValue12 < sensorMin12)
{
sensorMin12 = sensorValue12;
}
left12 = center12 - sensorMin12;
right12 = sensorMax12 - center12;
Serial.print("Center :");
Serial.print(center12);
Serial.print("Left :");
Serial.print(left12);
Serial.print("Right :");
Serial.print(right12);
Serial.println("");
EEPROM.put(360, center12);
delay(10);
EEPROM.put(370, left12);
delay(10);
EEPROM.put(380, right12);
delay(10);
}
// station 3
void callibSCP3()
{
delay(100);
lcd.clear();
lcd.setCursor (2, 0);
lcd.print ("Calib Station 3");
lcd.setCursor (3, 1);
lcd.print ("Sreering cont");
lcd.setCursor (7, 2);
lcd.print ("Move"); //and another load of these from A0 to A10
lcd.setCursor (4, 3);
lcd.print ("Port to Stbd");
sensorValue13 = analogRead(sensorPin13);
if (sensorValue13 > sensorMax13)
{
sensorMax13 = sensorValue13;
}
if (sensorValue13 < sensorMin13)
{
sensorMin13 = sensorValue13;
}
left13 = center13 - sensorMin13;
right13 = sensorMax13 - center13;
Serial.print("Center :");
Serial.print(center13);
Serial.print("Left :");
Serial.print(left13);
Serial.print("Right :");
Serial.print(right13);
Serial.println("");
EEPROM.put(390, center13);
delay(10);
EEPROM.put(400, left13);
delay(10);
EEPROM.put(410, right13);
delay(10);
}
void callibPDC3()
{
delay(100);
lcd.clear();
lcd.setCursor (2, 0);
lcd.print ("Calib Station 3");
lcd.setCursor (0, 1);
lcd.print ("Port deflector cont");
lcd.setCursor (7, 2);
lcd.print ("Move"); //and another load of these from A0 to A10
lcd.setCursor (3, 3);
lcd.print ("Ahead to Astern");
sensorValue14 = analogRead(sensorPin14);
if (sensorValue14 > sensorMax14)
{
sensorMax14 = sensorValue14;
}
if (sensorValue14 < sensorMin14)
{
sensorMin14 = sensorValue14;
}
left14 = center14 - sensorMin14;
right14 = sensorMax14 - center14;
Serial.print("Center :");
Serial.print(center14);
Serial.print("Left :");
Serial.print(left14);
Serial.print("Right :");
Serial.print(right14);
Serial.println("");
EEPROM.put(420, center14);
delay(10);
EEPROM.put(430, left14);
delay(10);
EEPROM.put(440, right14);
delay(10);
}
void callibstbd3()
{
delay(100);
lcd.clear();
lcd.setCursor (2, 0);
lcd.print ("Calib Station 3");
lcd.setCursor (0, 1);
lcd.print ("stbd deflector cont");
lcd.setCursor (7, 2);
lcd.print ("Move"); //and another load of these from A0 to A10
lcd.setCursor (3, 3);
lcd.print ("Ahead to Astern");
sensorValue15 = analogRead(sensorPin15);
if (sensorValue15 > sensorMax15)
{
sensorMax15 = sensorValue15;
}
if (sensorValue15 < sensorMin15)
{
sensorMin15 = sensorValue15;
}
left15 = center15 - sensorMin15;
right15 = sensorMax15 - center15;
Serial.print("Center :");
Serial.print(center15);
Serial.print("Left :");
Serial.print(left15);
Serial.print("Right :");
Serial.print(right15);
Serial.println("");
EEPROM.put(450, center15);
delay(10);
EEPROM.put(460, left15);
delay(10);
EEPROM.put(470, right15);
delay(10);
}
void callibpnf()
{
delay(100);
lcd.clear();
lcd.setCursor (2, 0);
lcd.print ("Calibration mode");
lcd.setCursor (5, 1);
lcd.print ("Port noz");
lcd.setCursor (7, 2);
lcd.print ("Move");
lcd.setCursor (4, 3);
lcd.print ("Port to Stbd");
sensorValue3 = analogRead(sensorPin3);
if (sensorValue3 > sensorMax3)
{
sensorMax3 = sensorValue3;
}
if (sensorValue3 < sensorMin3)
{
sensorMin3 = sensorValue3;
}
left3 = center3 - sensorMin3;
right3 = sensorMax3 - center3;
Serial.print("Center :");
Serial.print(center3);
Serial.print("Left :");
Serial.print(left3);
Serial.print("Right :");
Serial.print(right3);
Serial.println("");
EEPROM.put(90, center3);
delay(10);
EEPROM.put(100, left3);
delay(10);
EEPROM.put(110, right3);
delay(10);
}
void callibstbdnoz()
{
delay(100);
lcd.clear();
lcd.setCursor (2, 0);
lcd.print ("Calibration mode");
lcd.setCursor (5, 1);
lcd.print ("stbd noz");
lcd.setCursor (7, 2);
lcd.print ("Move"); //and another load of these from A0 to A10
lcd.setCursor (3, 3);
lcd.print ("port to stbd");
sensorValue4 = analogRead(sensorPin4);
if (sensorValue4 > sensorMax4)
{
sensorMax4 = sensorValue4;
}
if (sensorValue4 < sensorMin4)
{
sensorMin4 = sensorValue4;
}
left4 = center4 - sensorMin4;
right4 = sensorMax4 - center4;
Serial.print("Center :");
Serial.print(center4);
Serial.print("Left :");
Serial.print(left4);
Serial.print("Right :");
Serial.print(right4);
Serial.println("");
EEPROM.put(120, center4);
delay(10);
EEPROM.put(130, left4);
delay(10);
EEPROM.put(140, right4);
delay(10);
}
void callibpdf()
{
delay(100);
lcd.clear();
lcd.setCursor (2, 0);
lcd.print ("Calibration mode");
lcd.setCursor (5, 1);
lcd.print ("Port Deflector");
lcd.setCursor (7, 2);
lcd.print ("Move");
lcd.setCursor (3, 3);
lcd.print ("Ahead to Astern");
sensorValue5 = analogRead(sensorPin5);
if (sensorValue5 > sensorMax5)
{
sensorMax5 = sensorValue5;
}
if (sensorValue5 < sensorMin5)
{
sensorMin5 = sensorValue5;
}
left5 = center5 - sensorMin5;
right5 = sensorMax5 - center5;
Serial.print("Center :");
Serial.print(center5);
Serial.print("Left :");
Serial.print(left5);
Serial.print("Right :");
Serial.print(right5);
Serial.println("");
EEPROM.put(150, center5);
delay(10);
EEPROM.put(160, left5);
delay(10);
EEPROM.put(170, right5);
delay(10);
}
void callibstbdf()
{
delay(100);
lcd.clear();
lcd.setCursor (2, 0);
lcd.print ("Calibration mode");
lcd.setCursor (5, 1);
lcd.print ("stbd Deflector");
lcd.setCursor (7, 2);
lcd.print ("Move"); //and another load of these from A0 to A10
lcd.setCursor (3, 3);
lcd.print ("Ahead to Astern");
sensorValue6 = analogRead(sensorPin6);
if (sensorValue6 > sensorMax6)
{
sensorMax6 = sensorValue6;
}
if (sensorValue6 < sensorMin6)
{
sensorMin6 = sensorValue6;
}
left6 = center6 - sensorMin6;
right6 = sensorMax6 - center6;
Serial.print("Center :");
Serial.print(center6);
Serial.print("Left :");
Serial.print(left6);
Serial.print("Right :");
Serial.print(right6);
Serial.println("");
EEPROM.put(180, center6);
delay(10);
EEPROM.put(190, left6);
delay(10);
EEPROM.put(200, right6);
delay(10);
}
void callib()
{
while (flag_centers == 0)
{
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
digitalWrite(led4, LOW);
center = analogRead(sensorPin);
Serial.print("centers :");
Serial.print( center);
Serial.print(" ");
delay(10);
center1 = analogRead (sensorPin1);
Serial.print( center1);
Serial.print(" ");
delay(10);
center2 = analogRead (sensorPin2);
Serial.print( center2);
Serial.print(" ");
delay(10);
center3 = analogRead (sensorPin3);
Serial.print(center3);
Serial.print(" ");
delay(10);
center4 = analogRead (sensorPin4);
Serial.print( center4);
Serial.print(" ");
delay(10);
center5 = analogRead (sensorPin5);
Serial.print( center5);
Serial.print(" ");
delay(10);
center6 = analogRead (sensorPin6);
Serial.print( center6);
Serial.print(" ");
delay(10);
center7 = analogRead (sensorPin7);
Serial.print( center7);
Serial.print(" ");
delay(10);
center8 = analogRead (sensorPin8);
Serial.print( center8);
Serial.print(" ");
delay(10);
center9 = analogRead (sensorPin9);
Serial.print( center9);
Serial.print(" ");
delay(10);
center10 = analogRead (sensorPin10);
Serial.print( center10);
Serial.print(" ");
delay(10);
center11 = analogRead (sensorPin11);
Serial.print( center11);
Serial.print(" ");
delay(10);
center12 = analogRead (sensorPin12);
Serial.print( center12);
Serial.print(" ");
delay(10);
center13 = analogRead (sensorPin13);
Serial.print( center13);
Serial.print(" ");
delay(10);
center14 = analogRead (sensorPin14);
Serial.print( center14);
Serial.print(" ");
delay(10);
center15 = analogRead (sensorPin15);
Serial.print( center15);
Serial.print(" ");
Serial.println("");
delay(10);
flag_centers = 1;
}
while (flag_erase == 0)
{
eraseeeprom();
flag_erase = 1;
}
button.loop();
num = button.getCount();
switch (num)
{
case 1 :
{
callibSCP();
break;
}
case 2:
{
callibPDC();
break;
}
case 3:
{
callibstbd();
break;
}
case 4:
{
callibpnf();
break;
}
case 5:
{
callibstbdnoz();
break;
}
case 6:
{
callibpdf();
break;
}
case 7:
{
callibstbdf();
break;
}
case 8 :
{
callibSCP1();
break;
}
case 9:
{
callibPDC1();
break;
}
case 10:
{
callibstbd1();
break;
}
case 11 :
{
callibSCP2();
break;
}
case 12:
{
callibPDC2();
break;
}
case 13:
{
callibstbd2();
break;
}
case 14 :
{
callibSCP3();
break;
}
case 15:
{
callibPDC3();
break;
}
case 16:
{
callibstbd3();
break;
}
case 17:
{
delay(100);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Resetting");
delay(1000);
resetFunc();
break;
}
default:
{
lcd.setCursor (2, 0);
lcd.print ("Calibration mode");
delay(100);
lcd.clear();
}
}
}
void loadeprom()
{
EEPROM.get(0, Center);
delay(10);
EEPROM.get(10, Left);
delay(10);
EEPROM.get(20, Right);
delay(10);
EEPROM.get(30, Center1);
delay(10);
EEPROM.get(40, Left1);
delay(10);
EEPROM.get(50, Right1);
delay(10);
EEPROM.get(60, Center2);
delay(10);
EEPROM.get(70, Left2);
delay(10);
EEPROM.get(80, Right2);
delay(10);
EEPROM.get(90, Center3);
delay(10);
EEPROM.get(100, Left3);
delay(10);
EEPROM.get(110, Right3);
delay(10);
EEPROM.get(120, Center4);
delay(10);
EEPROM.get(130, Left4);
delay(10);
EEPROM.get(140, Right4);
delay(10);
EEPROM.get(150, Center5);
delay(10);
EEPROM.get(160, Left5);
delay(10);
EEPROM.get(170, Right5);
delay(10);
EEPROM.get(180, Center6);
delay(10);
EEPROM.get(190, Left6);
delay(10);
EEPROM.get(200, Right6);
delay(10);
EEPROM.get(210, Center7);
delay(10);
EEPROM.get(220, Left7);
delay(10);
EEPROM.get(230, Right7);
delay(10);
EEPROM.get(240, Center8);
delay(10);
EEPROM.get(250, Left8);
delay(10);
EEPROM.get(260, Right8);
delay(10);
EEPROM.get(270, Center9);
delay(10);
EEPROM.get(280, Left9);
delay(10);
EEPROM.get(290, Right9);
delay(10);
EEPROM.get(300, Center10);
delay(10);
EEPROM.get(310, Left10);
delay(10);
EEPROM.get(320, Right10);
delay(10);
EEPROM.get(330, Center11);
delay(10);
EEPROM.get(340, Left11);
delay(10);
EEPROM.get(350, Right11);
delay(10);
EEPROM.get(360, Center12);
delay(10);
EEPROM.get(370, Left12);
delay(10);
EEPROM.get(380, Right12);
delay(10);
EEPROM.get(390, Center13);
delay(10);
EEPROM.get(400, Left13);
delay(10);
EEPROM.get(410, Right13);
delay(10);
EEPROM.get(420, Center14);
delay(10);
EEPROM.get(430, Left14);
delay(10);
EEPROM.get(440, Right14);
delay(10);
EEPROM.get(450, Center15);
delay(10);
EEPROM.get(460, Left15);
delay(10);
EEPROM.get(470, Right15);
delay(10);
}
void boatrun()
{
buttonReading6 = digitalRead(switch6);
if (buttonReading6 == LOW && previous6 == HIGH)
{
flag_m = 1;
if (state6 == LOW)
{
state6 = HIGH;
}
else
{
state6 = LOW;
}
}
previous6 = buttonReading6;
if (state6 == HIGH && flag_m == 1)
{
flag_1 = 0;
flag_2 = 0;
flag_3 = 0;
sensorValue = analogRead(sensorPin);
sensorValue1 = analogRead(sensorPin1);
sensorValue2 = analogRead(sensorPin2);
sensorValue3 = analogRead(sensorPin3);
sensorValue4 = analogRead(sensorPin4);
sensorValue5 = analogRead(sensorPin5);
sensorValue6 = analogRead(sensorPin6);
if (sensorValue == Center) {
sensorValue = 128;
}
else
{
sensorValue = int(sensorValue < Center ? ((sensorValue - Center) * 128) / Left + 128 : (((sensorValue - Center) * 128) / Right + 128));
sensorValue = constrain(sensorValue, 0, 255); //was 256
intValue = int(sensorValue);
}
if (sensorValue1 == Center1) { //new
sensorValue1 = 128; //new
}
else
{
sensorValue1 = int(sensorValue1 < Center1 ? ((sensorValue1 - Center1) * 128) / Left1 + 128 : (((sensorValue1 - Center1) * 128) / Right1 + 128)); //new
sensorValue1 = constrain(sensorValue1, 0, 255); //new
intValue1 = int(sensorValue1);
}
if (sensorValue2 == Center2)
{
sensorValue2 = 128;
}
else
{
sensorValue2 = int(sensorValue2 < Center2 ? ((sensorValue2 - Center2) * 128) / Left2 + 128 : (((sensorValue2 - Center2) * 128) / Right2 + 128)); //new
sensorValue2 = constrain(sensorValue2, 0, 255);
intValue2 = int(sensorValue2);
}
if (sensorValue3 == Center3)
{
sensorValue3 = 128;
}
else
{
sensorValue3 = int(sensorValue3 < Center3 ? ((sensorValue3 - Center3) * 128) / Left3 + 128 : (((sensorValue3 - Center3) * 128) / Right3 + 128)); //new
sensorValue3 = constrain(sensorValue3, 0, 255);
intValue3 = int(sensorValue3);
// left portion
if (sensorValue3 < 128)
{
byte val3 = map(sensorValue3, 1, 128, 1, 32);
u8g.drawLine(32, 32, val3, 32);
u8g.drawLine(31, 31, val3, 31);
}
if (sensorValue3 > 128)
{
byte val3 = map(sensorValue3, 1, 128, 1, 31.9);
u8g.drawLine(32, 32, val3, 32);
u8g.drawLine(31, 31, val3, 31);
}
}
if (sensorValue4 == Center4)
{ //new
sensorValue4 = 128; //new
}
else
{
sensorValue4 = int(sensorValue4 < Center4 ? ((sensorValue4 - Center4) * 128) / Left4 + 128 : (((sensorValue4 - Center4) * 128) / Right4 + 128)); //new
sensorValue4 = constrain(sensorValue4, 0, 255); //new
intValue4 = int(sensorValue4);
if (sensorValue4 < 127)
{
byte val4 = map(sensorValue4, 1, 127, 64, 96);
u8g.drawLine(96, 32, val4, 32);
u8g.drawLine(95, 31, val4, 31);
}
if (sensorValue4 > 127)
{
byte val4 = map(sensorValue4, 1, 127, 64, 96);
u8g.drawLine(96, 32, val4, 32);
u8g.drawLine(95, 31, val4, 31);
}
}
if (sensorValue5 == Center5)
{
sensorValue5 = 128;
}
else
{
sensorValue5 = int(sensorValue5 < Center5 ? ((sensorValue5 - Center5) * 128) / Left5 + 128 : (((sensorValue5 - Center5) * 128) / Right5 + 128));
sensorValue5 = constrain(sensorValue5, 0, 255); //was 256
intValue5 = int(sensorValue5);
if (sensorValue5 < 128)
{
byte val5 = map(sensorValue5, 1, 127, 1, 31.9);
u8g.drawLine(32, 32, 32, val5);
u8g.drawLine(31, 31, 31, val5);
}
if (sensorValue5 > 128)
{
byte val5 = map(sensorValue5, 1, 127, 1, 32);
u8g.drawLine(32, 32, 32, val5);
u8g.drawLine(31, 31, 31, val5);
}
}
if (sensorValue6 == Center6)
{
sensorValue6 = 128;
}
else
{
sensorValue6 = int(sensorValue6 < Center6 ? ((sensorValue6 - Center6) * 128) / Left6 + 128 : (((sensorValue6 - Center6) * 128) / Right6 + 128));
sensorValue6 = constrain(sensorValue6, 0, 255); //was 256
intValue6 = int(sensorValue6);
if (sensorValue6 < 128)
{
byte val6 = map(sensorValue6, 1, 127, 1, 32);
u8g.drawLine(96, 32, 96, val6);
u8g.drawLine(95, 31, 95, val6);
}
if (sensorValue6 > 128)
{
byte val6 = map(sensorValue6, 1, 127, 1, 31.9);
u8g.drawLine(96, 32, 96, val6);
u8g.drawLine(95, 31, 95, val6);
}
}
delay(1);
//lcd.clear();
/*analogWrite(ledPin, intValue);
Serial.println(intValue);
Serial.print (" ,");
delay (250);*/
state4 = LOW;
state5 = LOW;
state3 = LOW;
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
digitalWrite(led4, HIGH);
lcd.setCursor (0, 0);
lcd.print("S.c"); //sterring controller
lcd.setCursor (6, 0);
lcd.print(sensorValue);
lcd.setCursor (10, 0);
lcd.print ("P.c"); //port deflector controller
lcd.setCursor (14, 0);
lcd.print (sensorValue1);
lcd.setCursor (0, 1);
lcd.print ("S.c"); //starboard deflector controller
lcd.setCursor (6, 1);
lcd.print (sensorValue2);
lcd.setCursor (10, 1);
lcd.print ("P.n"); //port nozzle feedback
lcd.setCursor (14, 1);
lcd.print (sensorValue3);
lcd.setCursor (0, 2);
lcd.print ("S.n"); //starboard nozzle feedback
lcd.setCursor (6, 2);
lcd.print (sensorValue4);
lcd.setCursor (10, 2);
lcd.print ("P.d"); //port deflector feedback
lcd.setCursor (14, 2);
lcd.print (sensorValue5);
lcd.setCursor (0, 3);
lcd.print ("S.d"); //starboard deflector feedback
lcd.setCursor (6, 3);
lcd.print (sensorValue6);
if(sensorValue - threshold > sensorValue3 )
{
digitalWrite(left_ram_p,HIGH);
digitalWrite(right_ram_p,LOW);
}
else if(sensorValue + threshold < sensorValue3 )
{
digitalWrite(left_ram_p,LOW);
digitalWrite(right_ram_p,HIGH);
}
else
{
digitalWrite(left_ram_p,HIGH);
digitalWrite(right_ram_p,HIGH);
}
//////////////////////////////////////
if(sensorValue - threshold > sensorValue4 )
{
digitalWrite(left_ram_s,HIGH);
digitalWrite(right_ram_s,LOW);
}
else if(sensorValue + threshold < sensorValue4 )
{
digitalWrite(left_ram_s,LOW);
digitalWrite(right_ram_s,HIGH);
}
else
{
digitalWrite(left_ram_s,HIGH);
digitalWrite(right_ram_s,HIGH);
}
//////////////////////////////////////
if(sensorValue1 - threshold > sensorValue5 )
{
digitalWrite(up_ram_p,HIGH);
digitalWrite(down_ram_p,LOW);
}
else if(sensorValue1 + threshold < sensorValue5 )
{
digitalWrite(up_ram_p,LOW);
digitalWrite(down_ram_p,HIGH);
}
else
{
digitalWrite(up_ram_p,HIGH);
digitalWrite(down_ram_p,HIGH);
}
//////////////////////////////////////
if(sensorValue2 - threshold > sensorValue6 )
{
digitalWrite(up_ram_s,HIGH);
digitalWrite(down_ram_s,LOW);
}
else if(sensorValue2 + threshold < sensorValue6 )
{
digitalWrite(up_ram_s,LOW);
digitalWrite(down_ram_s,HIGH);
}
else
{
digitalWrite(up_ram_s,HIGH);
digitalWrite(down_ram_s,HIGH);
}
//////////////////////////////////////
}
else
{
state6 = HIGH;
}
}
void station1()
{
buttonReading3 = digitalRead(switch3);
if (buttonReading3 == LOW && previous3 == HIGH )
{
flag_1 = 1;
if (state3 == LOW)
{
state3 = HIGH;
}
else
{
state3 = LOW;
}
}
previous3 = buttonReading3;
if (state3 == HIGH && flag_1 == 1)
{
flag_2 = 0;
flag_3 = 0;
flag_m = 0;
delay(500);
lcd.clear();
sensorValue7 = analogRead(sensorPin7);
sensorValue8 = analogRead(sensorPin8);
sensorValue9 = analogRead(sensorPin9);
if (sensorValue7 == Center7) {
sensorValue7 = 128;
}
else
{
sensorValue7 = int(sensorValue7 < Center7 ? ((sensorValue7 - Center7) * 128) / Left7 + 128 : (((sensorValue7 - Center7) * 128) / Right7 + 128));
sensorValue7 = constrain(sensorValue7, 0, 255); //was 256
intValue7 = int(sensorValue7);
}
if (sensorValue8 == Center8) { //new
sensorValue8 = 128; //new
}
else
{
sensorValue8 = int(sensorValue8 < Center8 ? ((sensorValue8 - Center8) * 128) / Left8 + 128 : (((sensorValue8 - Center8) * 128) / Right8 + 128)); //new
sensorValue8 = constrain(sensorValue8, 0, 255); //new
intValue8 = int(sensorValue8);
}
if (sensorValue9 == Center9)
{
sensorValue9 = 128;
}
else
{
sensorValue9 = int(sensorValue9 < Center9 ? ((sensorValue9 - Center9) * 128) / Left9 + 128 : (((sensorValue9 - Center9) * 128) / Right9 + 128)); //new
sensorValue9 = constrain(sensorValue9, 0, 255);
intValue9 = int(sensorValue9);
}
state4 = LOW;
state5 = LOW;
state6 = LOW;
digitalWrite(led1, HIGH);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
digitalWrite(led4, LOW);
lcd.setCursor (6, 0);
lcd.print("Station 1");
lcd.setCursor (6, 1);
lcd.print("Operational");
lcd.setCursor (0, 2);
lcd.print("S.c"); //sterring controller
lcd.setCursor (6, 2);
lcd.print(sensorValue7);
lcd.setCursor (10, 2);
lcd.print ("P.c"); //port deflector controller
lcd.setCursor (14, 2);
lcd.print (sensorValue8);
lcd.setCursor (0, 3);
lcd.print ("S.c"); //starboard deflector controller
lcd.setCursor (6, 3);
lcd.print (sensorValue9);
Serial.print("Center :");
Serial.print(Center9);
Serial.print("Left :");
Serial.print(Left9);
Serial.print("Right :");
Serial.print(Right9);
Serial.println("");
}
else
{
state3 = HIGH;
}
}
void station2()
{
buttonReading4 = digitalRead(switch4);
if (buttonReading4 == LOW && previous4 == HIGH )
{
flag_2 = 1;
if (state4 == LOW)
{
state4 = HIGH;
}
else
{
state4 = LOW;
}
}
previous4 = buttonReading4;
if (state4 == HIGH && flag_2 == 1)
{
flag_1 = 0;
flag_3 = 0;
flag_m = 0;
delay(500);
lcd.clear();
sensorValue10 = analogRead(sensorPin10);
sensorValue11 = analogRead(sensorPin11);
sensorValue12 = analogRead(sensorPin12);
if (sensorValue10 == Center10) {
sensorValue10 = 128;
}
else
{
sensorValue10 = int(sensorValue10 < Center10 ? ((sensorValue10 - Center10) * 128) / Left10 + 128 : (((sensorValue10 - Center10) * 128) / Right10 + 128));
sensorValue10 = constrain(sensorValue10, 0, 255); //was 256
intValue10 = int(sensorValue10);
}
if (sensorValue11 == Center11) { //new
sensorValue11 = 128; //new
}
else
{
sensorValue11 = int(sensorValue11 < Center11 ? ((sensorValue11 - Center11) * 128) / Left11 + 128 : (((sensorValue11 - Center11) * 128) / Right11 + 128)); //new
sensorValue11 = constrain(sensorValue11, 0, 255); //new
intValue11 = int(sensorValue11);
}
if (sensorValue12 == Center12)
{
sensorValue12 = 128;
}
else
{
sensorValue12 = int(sensorValue12 < Center12 ? ((sensorValue12 - Center12) * 128) / Left12 + 128 : (((sensorValue12 - Center12) * 128) / Right12 + 128)); //new
sensorValue12 = constrain(sensorValue12, 0, 255);
intValue12 = int(sensorValue12);
}
state3 = LOW;
state5 = LOW;
state6 = LOW;
digitalWrite(led1, LOW);
digitalWrite(led2, HIGH);
digitalWrite(led3, LOW);
digitalWrite(led4, LOW);
lcd.setCursor (6, 0);
lcd.print("Station 2");
lcd.setCursor (6, 1);
lcd.print("Operational");
lcd.setCursor (0, 2);
lcd.print("S.c"); //sterring controller
lcd.setCursor (6, 2);
lcd.print(sensorValue10);
lcd.setCursor (10, 2);
lcd.print ("P.c"); //port deflector controller
lcd.setCursor (14, 2);
lcd.print (sensorValue11);
lcd.setCursor (0, 3);
lcd.print ("S.c"); //starboard deflector controller
lcd.setCursor (6, 3);
lcd.print (sensorValue12);
Serial.print("Center :");
Serial.print(Center10);
Serial.print("Left :");
Serial.print(Left10);
Serial.print("Right :");
Serial.print(Right10);
Serial.println("");
}
else
{
state4 = HIGH;
}
}
void station3()
{
buttonReading5 = digitalRead(switch5);
if (buttonReading5 == LOW && previous5 == HIGH)
{
flag_3 = 1;
if (state5 == LOW)
{
state5 = HIGH;
}
else
{
state5 = LOW;
}
}
previous5 = buttonReading5;
if (state5 == HIGH && flag_3 == 1)
{
flag_1 = 0;
flag_2 = 0;
flag_m = 0;
delay(500);
lcd.clear();
sensorValue13 = analogRead(sensorPin13);
sensorValue14 = analogRead(sensorPin14);
sensorValue15 = analogRead(sensorPin15);
if (sensorValue13 == Center13) {
sensorValue13 = 128;
}
else
{
sensorValue13 = int(sensorValue13 < Center13 ? ((sensorValue13 - Center13) * 128) / Left13 + 128 : (((sensorValue13 - Center13) * 128) / Right13 + 128));
sensorValue13 = constrain(sensorValue13, 0, 255); //was 256
intValue13 = int(sensorValue13);
}
if (sensorValue14 == Center14) { //new
sensorValue14 = 128; //new
}
else
{
sensorValue14 = int(sensorValue14 < Center14 ? ((sensorValue14 - Center14) * 128) / Left14 + 128 : (((sensorValue14 - Center14) * 128) / Right14 + 128)); //new
sensorValue14 = constrain(sensorValue14, 0, 255); //new
intValue14 = int(sensorValue14);
}
if (sensorValue15 == Center15)
{
sensorValue15 = 128;
}
else
{
sensorValue15 = int(sensorValue15 < Center15 ? ((sensorValue15 - Center15) * 128) / Left15 + 128 : (((sensorValue15 - Center15) * 128) / Right15 + 128)); //new
sensorValue15 = constrain(sensorValue15, 0, 255);
intValue15 = int(sensorValue15);
}
state3 = LOW;
state4 = LOW;
state6 = LOW;
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, HIGH);
digitalWrite(led4, LOW);
lcd.setCursor (6, 0);
lcd.print("Station 3");
lcd.setCursor (6, 1);
lcd.print("Operational");
lcd.setCursor (0, 2);
lcd.print("S.c"); //sterring controller
lcd.setCursor (6, 2);
lcd.print(sensorValue13);
lcd.setCursor (10, 2);
lcd.print ("P.c"); //port deflector controller
lcd.setCursor (14, 2);
lcd.print (sensorValue14);
lcd.setCursor (0, 3);
lcd.print ("S.c"); //starboard deflector controller
lcd.setCursor (6, 3);
lcd.print (sensorValue15);
Serial.print("Center :");
Serial.print(Center15);
Serial.print("Left :");
Serial.print(Left15);
Serial.print("Right :");
Serial.print(Right15);
Serial.println("");
}
else
{
state5 = HIGH;
}
}
void loop()
{
u8g.firstPage();
do
{
u8g.drawFrame(0, 0, 127, 63);
u8g.drawFrame(1, 1, 126, 62);
u8g.drawDisc(32, 32, 1);
u8g.drawDisc(96, 32, 1);
u8g.drawLine(63, 0, 63, 63);
u8g.drawLine(62, 0, 62, 62);
buttonReading2 = digitalRead(switch2);
if (buttonReading2 == LOW && previous2 == HIGH)
{
if (state2 == LOW)
{
state2 = HIGH;
}
else
{
state2 = LOW;
}
}
previous2 = buttonReading2;
if (state2 == HIGH)
{
callib();
}
else
{
g_mainstation();
boatrun();
station1();
station2();
station3();
}
} while (u8g.nextPage());
}