//[email protected] - 2024-07-29
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2); // TINKERCAD WANTS THIS TO BE LiquidCrystal_I2C lcd(32,16,2);
int timedata = A0; // analog pin0 , a Potentiometer is connected with A0 pin of Arduino.
int timerawdata = 0; // stores the value coming from the Potentiometer.
int settime = 1; // time duration in milliseconds (initial value)
int startb = 0; // button to start the welding
int relay = 2; // the output relay
int ReadyLed = 3; // when this LED is turned ON, it means you can start the welding
int Sflag = 0; // stops the unnecessary repetition of code.
int spotcount = 0; // counts the amount of spot welds
int refresh = HIGH; // refresh the display
int forceddelay = 500; // forced delay between pulses (ms)
void setup(){
Serial.begin(9600);
lcd.init();
lcd.begin(16,2);
lcd.backlight();
pinMode(startb, INPUT_PULLUP);
digitalWrite(startb, HIGH);
pinMode(timedata, INPUT); // POTENTIOMETER CONNECTED
pinMode(relay, OUTPUT);
digitalWrite(relay, LOW);
pinMode(ReadyLed, OUTPUT);
delay(100);
digitalWrite(ReadyLed, HIGH);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("melissa ");
lcd.setCursor(0, 1);
lcd.print("VERSION 1.0");
delay (2000);
lcd.clear();
}
void loop(){
if (timerawdata - 100 >= analogRead(timedata) ||timerawdata + 100 <= analogRead(timedata) ){
timerawdata = analogRead(timedata);
settime = map(timerawdata, 0, 1023, 10, 1000); // 0.1 to 1000 milliseconds
refresh = HIGH;
Serial.println("refresh");
}
if (digitalRead(startb) == LOW){
digitalWrite(ReadyLed, LOW);
digitalWrite(relay, HIGH);
delay(settime);
digitalWrite(relay, LOW);
digitalWrite(ReadyLed, HIGH);
spotcount = spotcount + 1;
refresh = HIGH;
}
if (refresh == HIGH){
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("ON Time:");
lcd.print(settime);
lcd.print("ms");
lcd.setCursor(0, 1);
lcd.print("Pulses:");
lcd.print(spotcount);
refresh = LOW;
}
if (spotcount > 0 && settime < forceddelay){
delay (forceddelay - settime);
}
if (digitalRead(startb) == HIGH && spotcount != 0) {
spotcount = 0;
}
}