#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 20, 4);
int continuousPin = 6, automaticPin = 4; //Wahlschalter für manuelles Schweißen und Schweißen mit Timer
int startPin = 5; //Start Taster
int relaisPin = 7; //Solid-State-Relais Ausgang
int delayPin = A0; //Poti für Schweißzeit
int ledPinCont = 11, ledPinAuto = 13, ledPinWelding = 12;
bool oldMode = 0;
int weldingMS = 0;
void setup() {
Serial.begin(9600);
pinMode(continuousPin, INPUT_PULLUP);
pinMode(automaticPin, INPUT_PULLUP);
pinMode(startPin, INPUT_PULLUP);
pinMode(delayPin, INPUT);
pinMode(relaisPin, OUTPUT);
lcd.init();
lcd.backlight();
// lcd.setCursor(Zeichen, Zeile);
}
void loop() {
bool continuous = digitalRead(continuousPin);
bool automatic = digitalRead(automaticPin);
int time = map(analogRead(delayPin), 0, 1023, 0, 100) * 50;
if(time != weldingMS) {
weldingMS = time;
}
if (digitalRead(startPin) != LOW) {
lcd.setCursor(0, 0);
lcd.print("Current Mode: ");
lcd.setCursor(0, 1);
if(continuous) {
lcd.print("Continuous / Manual ");
lcd.setCursor(0, 2);
lcd.print(" ");
lcd.setCursor(0, 3);
lcd.print("Ready to Weld! ");
} else if (automatic) {
lcd.print("Automatic / Timer ");
lcd.setCursor(0, 2);
lcd.print("Welding time: ");
lcd.setCursor(14, 2);
lcd.print(weldingMS);
lcd.setCursor(0, 3);
lcd.print("Ready to Weld! ");
}
}
if(continuous && !automatic) {
if(oldMode != 0) {
oldMode = 0;
}
weldContinuous();
} else if(!continuous && automatic) {
if(oldMode != 1) {
oldMode = 1;
}
weldWithTimer(weldingMS);
}
delay(10);
}
void weldWithTimer(int timerMS) {
if(!digitalRead(startPin)) {
lcd.setCursor(0, 0);
lcd.print("Welding!!! ");
lcd.setCursor(0, 1);
lcd.print(" ");
lcd.setCursor(0, 2);
lcd.print("Time remaining: ");
lcd.setCursor(0, 3);
lcd.print(" ");
digitalWrite(relaisPin, HIGH);
for(int i = timerMS; i > 0; i -= 50) {
lcd.setCursor(0, 1);
lcd.print(" ");
lcd.print((i));
if(i < 1000) {
lcd.setCursor(3, 3);
lcd.print("ms ");
} else if(i >= 1000) {
lcd.setCursor(4, 3);
lcd.print("ms ");
}
delay(50);
}
digitalWrite(relaisPin, LOW);
}
}
void weldContinuous() {
if (digitalRead(startPin) != LOW) {
digitalWrite(relaisPin, LOW);
} else {
lcd.setCursor(0, 0);
lcd.print("Welding!!! ");
lcd.setCursor(0, 1);
lcd.print(" ");
lcd.setCursor(0, 2);
lcd.print(" ");
lcd.setCursor(0, 3);
lcd.print(" ");
digitalWrite(relaisPin, HIGH);
}
}