#include <EasyNextionLibrary.h>
#include <trigger.h>
#include "Nextion.h"
#include <Bounce2.h>
NexButton b4 = NexButton(0, 6, "b4"); // ALL ON
NexButton b5 = NexButton(0, 7, "b5"); // ALL OFF
//Digital Inputs
const int Air_Pressure_OK = 22;
const int Coarse_Sys_Button = 24;
const int Mill_Sys_Button = 25;
const int Mold_Sys_Button = 26;
const int Auger_Switch = 27;
const int Coarse_Half_Limit = 28;
const int Coarse_Full_Limit = 29;
const int Powder_Full_Limit = 30;
//Analog In
const int Current_Sensor_Read = A15;
int Sensitivity = 188;
int Current_Read_Value = 0;
int offsetVoltage = 25000;
double ReadVoltage = 0;
double RealCurrent = 0;
//Digital Outputs
const int Alarm_Strobe = 42;
const int Pulsers_On_LED = 43;
const int Coarse_Blower_Relay = 44;
const int Coarse_Al_Relay = 45; //Al is air lock//
const int Transfer_Blower_Relay = 46;
const int Millshop_Blower_Relay = 47;
const int Millshop_Al_Relay = 48;
const int Molder_Blower_Relay = 49;
const int Molder_Al_Relay = 50;
const int Coarse_Powder_Al = 51;
const int Coarse_Top_Al = 52;
const int Auger_Relay = 53;
Bounce myInputPin1 = Bounce();
Bounce myInputPin2 = Bounce();
Bounce myInputPin3 = Bounce();
//Pin State
byte Coarse_Button_State = LOW;
boolean offDelayTimer_1 = false;
byte Mill_Button_State = LOW;
boolean offDelayTimer_2 = false;
byte Mold_Button_State = LOW;
boolean offDelayTimer_3 = false;
//Times
unsigned long lastDebounce_1;
unsigned long debounceDelay_1 = 5000;
unsigned long lastDebounce_2;
unsigned long debounceDelay_2 = 5000;
unsigned long lastDebounce_3;
unsigned long debounceDelay_3 = 5000;
void setup()
{
Serial.begin(9600);
//Set Pin IO
pinMode(Air_Pressure_OK, INPUT_PULLUP);
pinMode(Coarse_Sys_Button, INPUT_PULLUP);
pinMode(Mill_Sys_Button, INPUT_PULLUP);
pinMode(Mold_Sys_Button, INPUT_PULLUP);
pinMode(Auger_Switch, INPUT_PULLUP);
pinMode(Coarse_Half_Limit, INPUT_PULLUP);
pinMode(Coarse_Full_Limit, INPUT_PULLUP);
pinMode(Powder_Full_Limit, INPUT_PULLUP);
pinMode(Current_Sensor_Read, INPUT);
myInputPin1.attach(Coarse_Sys_Button);
myInputPin1.interval(50);
myInputPin2.attach(Mill_Sys_Button);
myInputPin2.interval(50);
myInputPin3.attach(Mold_Sys_Button);
myInputPin3.interval(50);
pinMode(Alarm_Strobe, OUTPUT);
pinMode(Pulsers_On_LED, OUTPUT);
pinMode(Coarse_Blower_Relay, OUTPUT);
pinMode(Coarse_Al_Relay, OUTPUT);
pinMode(Transfer_Blower_Relay, OUTPUT);
pinMode(Millshop_Blower_Relay, OUTPUT);
pinMode(Millshop_Al_Relay, OUTPUT);
pinMode(Molder_Blower_Relay, OUTPUT);
pinMode(Molder_Al_Relay, OUTPUT);
pinMode(Coarse_Powder_Al, OUTPUT);
pinMode(Coarse_Top_Al, OUTPUT);
pinMode(Auger_Relay, OUTPUT);
//Set Pin Status
digitalWrite(Alarm_Strobe, HIGH);
digitalWrite(Pulsers_On_LED, HIGH);
digitalWrite(Coarse_Blower_Relay, HIGH);
digitalWrite(Coarse_Al_Relay, HIGH);
digitalWrite(Transfer_Blower_Relay, HIGH);
digitalWrite(Millshop_Blower_Relay, HIGH);
digitalWrite(Millshop_Al_Relay, HIGH);
digitalWrite(Molder_Blower_Relay, HIGH);
digitalWrite(Molder_Al_Relay, HIGH);
digitalWrite(Coarse_Powder_Al, HIGH);
digitalWrite(Coarse_Top_Al, HIGH);
digitalWrite(Auger_Relay, HIGH);
}
void loop()
{
myInputPin1.update();
myInputPin2.update();
myInputPin3.update();
if (myInputPin1.fell() && Coarse_Button_State == LOW )
{
digitalWrite(Coarse_Blower_Relay, LOW );//instant turn on
delay(500);
digitalWrite(Coarse_Al_Relay, LOW );
delay(500);
digitalWrite(Transfer_Blower_Relay, LOW );
delay(500);
digitalWrite(Coarse_Powder_Al, LOW );
delay(500);
digitalWrite(Coarse_Top_Al, LOW );
Coarse_Button_State = HIGH;
Serial.println("Coarse_On");
}
else if (myInputPin1.fell() && Coarse_Button_State == HIGH)
{
offDelayTimer_1 = true;
lastDebounce_1 = millis();
}
if (offDelayTimer_1)
{
if (millis() - lastDebounce_1 >= debounceDelay_1)
{
digitalWrite(Coarse_Blower_Relay, HIGH );//delay turn off
digitalWrite(Coarse_Al_Relay, HIGH );
Coarse_Button_State = LOW;
Serial.println("Coarse_Off");
offDelayTimer_1 = false;
if(Mold_Button_State == LOW && Mill_Button_State == LOW)
{
digitalWrite(Transfer_Blower_Relay, HIGH );
digitalWrite(Coarse_Powder_Al, HIGH );
digitalWrite(Coarse_Top_Al, HIGH );
}
}
}
if (myInputPin2.fell() && Mill_Button_State == LOW )
{
digitalWrite(Millshop_Blower_Relay, LOW );//instant turn on
delay(500);
digitalWrite(Millshop_Al_Relay, LOW );
delay(500);
digitalWrite(Transfer_Blower_Relay, LOW );
delay(500);
digitalWrite(Coarse_Powder_Al,LOW );
delay(500);
digitalWrite(Coarse_Top_Al, LOW );
Mill_Button_State = HIGH;
Serial.println("MillShop_On");
}
else if (myInputPin2.fell() && Mill_Button_State == HIGH)
{
offDelayTimer_2 = true;
lastDebounce_2 = millis();
}
if (offDelayTimer_2)
{
if (millis() - lastDebounce_2 >= debounceDelay_2)
{
digitalWrite(Millshop_Blower_Relay, HIGH );//delay turn off
digitalWrite(Millshop_Al_Relay, HIGH );
if(Coarse_Button_State == LOW && Mold_Button_State == LOW)
{
digitalWrite(Transfer_Blower_Relay, HIGH );
digitalWrite(Coarse_Powder_Al, HIGH );
digitalWrite(Coarse_Top_Al, HIGH );
}
Mill_Button_State = LOW;
Serial.println("MillShop_Off");
offDelayTimer_2 = false;
}
}
if (myInputPin3.fell() && Mold_Button_State == LOW )
{
digitalWrite(Molder_Blower_Relay, LOW );//instant turn on
delay(500);
digitalWrite(Molder_Al_Relay, LOW );
delay(500);
digitalWrite(Transfer_Blower_Relay, LOW );
delay(500);
digitalWrite(Coarse_Powder_Al, LOW );
delay(500);
digitalWrite(Coarse_Top_Al, LOW );
Mold_Button_State = HIGH;
Serial.println("Molder_On");
}
else if (myInputPin3.fell() && Mold_Button_State == HIGH)
{
offDelayTimer_3 = true;
lastDebounce_3 = millis();
}
if (offDelayTimer_3)
{
if (millis() - lastDebounce_3 >= debounceDelay_3)
{
digitalWrite(Molder_Blower_Relay, HIGH );//delay turn off
digitalWrite(Molder_Al_Relay, HIGH );
if(Coarse_Button_State == LOW && Mill_Button_State == LOW)
{
digitalWrite(Transfer_Blower_Relay, HIGH );
digitalWrite(Coarse_Powder_Al, HIGH );
digitalWrite(Coarse_Top_Al, HIGH );
}
Mold_Button_State = LOW;
Serial.println("Molder_Off");
offDelayTimer_3 = false;
}
}
if (digitalRead(Coarse_Half_Limit)== LOW or digitalRead(Auger_Switch)== LOW)
{
digitalWrite(Auger_Relay, LOW);
}
else{
digitalWrite(Auger_Relay, HIGH);
}
if (digitalRead(Coarse_Full_Limit)==LOW or digitalRead(Powder_Full_Limit) == LOW)
{
digitalWrite(Alarm_Strobe, LOW);
}
else{
digitalWrite(Alarm_Strobe, HIGH);
}
if (digitalRead(Air_Pressure_OK) == LOW)
{
digitalWrite(Pulsers_On_LED, LOW);
}
else{
digitalWrite(Pulsers_On_LED, HIGH);
}
Current_Read_Value = analogRead(Current_Sensor_Read);
ReadVoltage = (Current_Read_Value)*50000/1024;
RealCurrent = ((offsetVoltage - ReadVoltage)/Sensitivity);
delay(1000);
if(digitalRead(Auger_Relay) == LOW){
Serial.print(" Current Reading ");
Serial.print(RealCurrent);
Serial.print(" mA");
Serial.println();
}
}
NexButton b4 = NexButton(0, 6, "b4"); // ALL ON
I want this button to change the state of all buttons to true.
NexButton b5 = NexButton(0, 7, "b5"); // ALL OFF
I want this button to change the state of all buttons to false, this way the selected timers will be carried out.
I have a physical button for an E-Stop that is tied to the reset pin, but that one does not follow the timer off.
I have number boxes with global numeric pads set to them that I want to adjust these values,
//Times
unsigned long lastDebounce_1;
unsigned long debounceDelay_1 = 5000;
unsigned long lastDebounce_2;
unsigned long debounceDelay_2 = 5000;
unsigned long lastDebounce_3;
unsigned long debounceDelay_3 = 5000;
I have number boxes that I want to simply display this value.
Serial.print(RealCurrent);
And finally, I want to be able to send alarms in certain scenarios.
Now, I am obviously NOT ASKING ANYONE TO DO THIS FOR ME! Just need some help getting started.
Thank you for your help!