//#include <Wire.h>
#include <SPI.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);//3F veya 27
#define LCD_LIGHT_PIN 6 // LCD arka ışığı pini
const int onbutton = 13 ; //DI13 ON / STRT butonu olarak belirlendi
const int stpbutton = 12 ; //DI12 STOP butonu olarak belirlendi
const int lcbutton = A1 ; //A1 LOCAL / REMOTE butonu olarak belirlendi
const int crbutton = A6 ; //A6 Sirkülasyon yönü butonu olarak belirlendi
const int nzbutton = A7 ; //A7 Nozul yönü butonu olarak belirlendi
const int gpbutton = A2 ; //A2 Gaz + butonu olarak belirlendi
const int gnbutton = A3 ; //A3 Gsz - butonu olarak belirlendi
int RLON = 6;
int RLSTRT = 5;
int RLSTP = 4;
int RLLC = 11;
int RLCR = 8;
int RLNZ = 7;
int RLGP = 9;
int RLGN = 10;
#define BAT A0
int onmode = LOW;
int strtmode = LOW;
int stpmode = LOW;
int enginemode = LOW;
int controlmode = LOW;
int vanamode = LOW;
int vanatimer = 0;
int gazmode = LOW;
int gazimer = 0;
int buttonState1 = LOW;
int lastButtonState1 = LOW;
int buttonState2 = LOW;
int lastButtonState2 = LOW;
int buttonState3 = LOW;
int lastButtonState3 = LOW;
int buttonState4 = LOW;
int lastButtonState4 = LOW;
int buttonState5 = LOW;
int lastButtonState5 = LOW;
int buttonState6 = LOW;
int lastButtonState6 = LOW;
int buttonState7 = LOW;
int lastButtonState7 = LOW;
unsigned long lastDebounceTime1 = 0;
unsigned long debounceDelay1 = 20;
unsigned long lastDebounceTime2 = 0;
unsigned long debounceDelay2 = 20;
unsigned long lastDebounceTime3 = 0;
unsigned long debounceDelay3 = 20;
unsigned long lastDebounceTime4 = 0;
unsigned long debounceDelay4 = 20;
unsigned long lastDebounceTime5 = 0;
unsigned long debounceDelay5 = 20;
unsigned long lastDebounceTime6 = 0;
unsigned long debounceDelay6 = 20;
unsigned long lastDebounceTime7 = 0;
unsigned long debounceDelay7 = 20;
int motortime = 5;
int restartdelay = 0;
void setup() {
pinMode(RLON, OUTPUT);
pinMode(RLSTRT, OUTPUT);
pinMode(RLSTP, OUTPUT);
pinMode(RLLC, OUTPUT);
pinMode(RLCR, OUTPUT);
pinMode(RLNZ, OUTPUT);
pinMode(RLGP, OUTPUT);
pinMode(RLGN, OUTPUT);
digitalWrite(RLON, HIGH); //
digitalWrite(RLSTRT, HIGH); //
digitalWrite(RLSTP, HIGH); //
digitalWrite(RLLC, HIGH); //
digitalWrite(RLCR, HIGH); //
digitalWrite(RLNZ, HIGH); //
digitalWrite(RLGP, HIGH); //
digitalWrite(RLGN, HIGH); //
pinMode(LCD_LIGHT_PIN, OUTPUT); // LCD Arka Işığı
digitalWrite(LCD_LIGHT_PIN, HIGH); // LCD Arka Işığını Aç
lcd.init();
lcd.backlight();
pinMode(12, INPUT) ; //
pinMode(13, INPUT) ; //
pinMode(A1, INPUT) ; //
pinMode(A6, INPUT) ; //
pinMode(A7, INPUT) ; //
pinMode(A3, INPUT) ; //
pinMode(A2, INPUT) ; //
lcd.setCursor(0, 0);
lcd.print(" SIRIORI ");
lcd.setCursor(0, 1);
lcd.print(" Ver. 5 _ 01 ");
delay(2000);
lcd.clear();
int voltaj = map(analogRead(BAT), 0, 1023, 0, 125);
float batery = voltaj/10;
lcd.setCursor(0, 0);
lcd.print("Batery : ");
lcd.setCursor(10, 0);
lcd.print(batery);
delay(1500);
lcd.setCursor(0, 0);
lcd.print("PRESS ON BUTTON ");
lcd.setCursor(0, 1);
lcd.print(" FOR START ");
}
void loop(){
//----------------------------------------------------------------
// Init ayarları
if (onmode == LOW)
{
digitalWrite(RLCR, LOW); //
digitalWrite(RLNZ, HIGH); //
digitalWrite(RLGP, HIGH); //
digitalWrite(RLGN, LOW); //
}
//----------------------------------------------------------------
// ON Butonuna basıldığında Power On
int reading1 = digitalRead(onbutton);
if (reading1 != lastButtonState1)
{
lastDebounceTime1 = millis();
}
delay(100);
int time1 = (millis() - lastDebounceTime1);
if ((millis() - lastDebounceTime1) > debounceDelay1) {
if (reading1 != buttonState1)
{
buttonState1 = reading1;
if (buttonState1 == HIGH)
{
if (onmode == LOW )
{
lcd.setCursor(0, 0);
lcd.print(" ");
lcd.setCursor(0, 1);
lcd.print(" POWER ON ");
digitalWrite(RLON, LOW);
onmode = HIGH;
}
}
}
}
if (onmode == HIGH && reading1 == LOW )
{
restartdelay = restartdelay +1;
}
//----------------------------------------------------------------
// ON Butonuna basıldığında Starter Run
if (reading1 == HIGH)
{
if (onmode == HIGH && restartdelay >= 5 && strtmode == LOW )
{
lcd.setCursor(0, 0);
lcd.print(" ");
lcd.setCursor(0, 1);
lcd.print("ENGINE STARTING ");
delay (20);
digitalWrite(RLSTRT, LOW);
strtmode = HIGH;
}
if (onmode == HIGH && restartdelay >= 5 && strtmode == HIGH )
{
lcd.setCursor(0, 1);
lcd.print(" ");
lcd.setCursor(0, 1);
lcd.print(" ENGINE STARTED ");
delay (200);
lcd.setCursor(0, 1);
lcd.print(" ENGINE RUNNING ");
digitalWrite(RLSTRT, HIGH);
strtmode = LOW;
restartdelay=0;
}
}
//----------------------------------------------------------------
// STOP Butonuna basıldığında
int reading2 = digitalRead(stpbutton);
if (reading2 != lastButtonState2)
{
lastDebounceTime2 = millis();
}
delay(100);
if ((millis() - lastDebounceTime2) > debounceDelay2)
{
if (reading2 != buttonState2)
{
buttonState2 = reading2;
if (buttonState2 == HIGH)
{
if (onmode == HIGH)
{
digitalWrite(RLSTP, HIGH);
delay(500);
digitalWrite(RLSTP, LOW);
digitalWrite(RLON, HIGH);
lcd.setCursor(0, 0);
lcd.print(" ");
lcd.setCursor(0, 1);
lcd.print(" ENGINE STOPING ");
stpmode = HIGH;
enginemode = LOW;
onmode = LOW;
restartdelay = 0;
delay(1000);
lcd.setCursor(0, 0);
lcd.print("PRESS ON BUTTON ");
lcd.setCursor(0, 1);
lcd.print(" FOR START ");
}
}
}
}
//----------------------------------------------------------------
// LOCAL / REMOTE Butonuna basıldığında
int reading3 = digitalRead(lcbutton);
if (reading3 != lastButtonState3)
{
lastDebounceTime3 = millis();
}
delay(100);
if ((millis() - lastDebounceTime3) > debounceDelay3)
{
if (reading3 != buttonState3)
{
buttonState3 = reading3;
if (buttonState3 == HIGH)
{
controlmode = !controlmode;
}
}
}
if (controlmode == LOW && onmode==HIGH )
{
lcd.setCursor(0, 0);
lcd.print("LOCAL ");
digitalWrite(RLLC, HIGH);
delay (50);
}
if (controlmode == HIGH && onmode==HIGH)
{
lcd.setCursor(0, 0);
lcd.print("REMOTE");
digitalWrite(RLLC, LOW);
delay (50);
}
//----------------------------------------------------------------
// CR Kumanda Butonuna basıldığında
int reading4 = digitalRead(crbutton);
if (reading4 != lastButtonState4)
{
lastDebounceTime4 = millis();
}
delay(100);
if ((millis() - lastDebounceTime4) > debounceDelay4) {
if (reading4 != buttonState4)
{
buttonState4 = reading4;
if (buttonState4 == HIGH)
{
if (vanamode == HIGH)
{
vanamode = LOW;
vanatimer=0;
}
}
}
}
if (vanamode==LOW && vanatimer < motortime && onmode == HIGH)
{
lcd.setCursor(7, 0);
lcd.print("CIRC>>");
digitalWrite(RLCR, LOW);
digitalWrite(RLNZ, HIGH);
vanatimer=vanatimer + 1;
}
//----------------------------------------------------------------
// NZ Kumanda Butonuna basıldığında
int reading5 = digitalRead(nzbutton);
if (reading5 != lastButtonState5)
{
lastDebounceTime5 = millis();
}
delay(100);
if ((millis() - lastDebounceTime5) > debounceDelay5) {
if (reading5 != buttonState5)
{
buttonState5 = reading5;
if (buttonState5 == HIGH)
{
if (vanamode == LOW)
{
vanamode = HIGH;
vanatimer=0;
}
}
}
}
if (vanamode==HIGH && vanatimer < motortime && onmode == HIGH)
{
lcd.setCursor(7, 0);
lcd.print("NOZZ>>");
digitalWrite(RLCR, HIGH);
digitalWrite(RLNZ, LOW);
vanatimer=vanatimer + 1;
}
if (vanamode==HIGH && vanatimer >= motortime && onmode == HIGH)
{
lcd.setCursor(7, 0);
lcd.print("NOZZLE");
}
if (vanamode==LOW && vanatimer >= motortime && onmode == HIGH)
{
lcd.setCursor(7, 0);
lcd.print("CIRCLE");
}
//----------------------------------------------------------------
// G+ Kumanda Butonuna basıldığında
int reading6 = digitalRead(gpbutton);
if (reading6 != lastButtonState6)
{
lastDebounceTime6 = millis();
}
delay(100);
if ((millis() - lastDebounceTime6) > debounceDelay6) {
if (reading6 != buttonState6)
{
buttonState6 = reading6;
if (buttonState6 == HIGH && onmode == HIGH)
{
lcd.setCursor(14, 0);
lcd.print("G+");
digitalWrite(RLGP, LOW);
digitalWrite(RLGN, HIGH);
delay (500);
digitalWrite(RLGP, HIGH);
digitalWrite(RLGN, HIGH);
lcd.setCursor(14, 0);
lcd.print(" ");
}
}
}
//----------------------------------------------------------------
// G- Kumanda Butonuna basıldığında
int reading7 = digitalRead(gnbutton);
if (reading7 != lastButtonState7)
{
lastDebounceTime7 = millis();
}
delay(100);
if ((millis() - lastDebounceTime7) > debounceDelay7) {
if (reading7 != buttonState7)
{
buttonState7 = reading7;
if (buttonState7 == HIGH && onmode == HIGH)
{
lcd.setCursor(14, 0);
lcd.print("G-");
digitalWrite(RLGN, LOW);
digitalWrite(RLGP, HIGH);
delay (500);
digitalWrite(RLGN, HIGH);
digitalWrite(RLGP, HIGH);
lcd.setCursor(14, 0);
lcd.print(" ");
}
}
}
//----------------------------------------------------------------
}