#include <Arduino.h>
#include <Wire.h>
#include <stdbool.h>
#include <stdint.h>
constexpr uint8_t buttonPin1 = 2;
//constexpr uint8_t buttonPin2 = 3;
uint8_t buttonState1 = 0; // variable for reading the pushbutton status
//uint8_t buttonState2 = 0;
constexpr uint8_t IN11 = 4; // Modul 1, 1.st relay //Start
constexpr uint8_t IN12 = 5; // Modul 1, 2.st relay //F1
constexpr uint8_t IN21 = 6; // Modul 2, 1.st relay //UP Arrow
constexpr uint8_t IN22 = 7; // Modul 2, 1.st relay //Down Arrow
#define ON 1
#define OFF 0
double PrintingTime = 4; // Time that maschine needs for printing one layer
double CuringTime = 20; // Time for curing one layer
double OnePrintingProcesstime = (PrintingTime + CuringTime);// Total time between to prints
//int OffContactCount = 4; // Number of Off contact that needs to be increased
int OffContact = 1 ;
int OffContactNumToPrint = 0;
int TotalPrintingCount = 10; // Number of total layer to be printed
int ActualPrintingCount = 0; //Number of actual printed layer until Stop of Process
int PartialPrintingCount = 10; /* Number of layers to be printed
until OFF contact needs to be increased*/
// Functions*************************
// Delay Function
void delaySelbst(double delayTime) // the Output is in second
{
for ( int i = 0 ; i < (20*delayTime) ; i++){
delay(50);
}
}
//set the status of relays
void relay_SetStatus( unsigned char
status_1, unsigned char status_2, unsigned char status_3, unsigned char status_4)
{
digitalWrite(IN11, status_1);
digitalWrite(IN12, status_2);
digitalWrite(IN21, status_3);
digitalWrite(IN22, status_4);
}
//initialize the relay
void relay_init()
{
//set all the relays OUTPUT
pinMode(IN11, OUTPUT);
pinMode(IN12, OUTPUT);
pinMode(IN21, OUTPUT);
pinMode(IN22, OUTPUT);
relay_SetStatus( OFF, OFF , OFF , OFF );
//turn off all the relay
}
void Siebdruck(){
float t_start_funk = millis();
for (int a = 0 ; a < TotalPrintingCount ; a++)
{
//relay_init(); //initialize the relay
for (int b = 0 ; b < PartialPrintingCount ; b++)
{
relay_init(); //initialize the relay
//Start
relay_SetStatus(ON,OFF,OFF,OFF);
delaySelbst(0.5); // the time for Relay start and stop
relay_SetStatus(OFF,OFF,OFF,OFF);
delaySelbst(OnePrintingProcesstime);
++ActualPrintingCount;
}
Serial.println("ActualPrintingCount = ");
Serial.println(ActualPrintingCount);
//if (ActualPrintingCount =! TotalPrintingCount)
{
//F1
relay_SetStatus(OFF,ON,OFF,OFF);
delaySelbst(0.5); // the time for Relay start and stop
relay_SetStatus(OFF,OFF,OFF,OFF);
delaySelbst(0.5);
Serial.println("ertes,F1 Gedruckt");
for (int c = 0 ; c < OffContact ; c++)
{
//UP ARROW
relay_SetStatus(OFF,OFF,ON,OFF);
delaySelbst(0.5); // the time for Relay start and stop
relay_SetStatus(OFF,OFF,OFF,OFF);
delaySelbst(0.5);
++OffContactNumToPrint;
}
}
}
float t_end_funk = millis();
float t_deff = (t_end_funk - t_start_funk);
Serial.println("ActualPrintingCount =");
Serial.println(ActualPrintingCount);
Serial.println("OffContactCount =");
Serial.println(OffContactNumToPrint);
Serial.println("ActualPrintingTime =");
Serial.println(t_deff);
//F1
relay_SetStatus(OFF,ON,OFF,OFF);
delaySelbst(0.5); // the time for Relay start and stop
relay_SetStatus(OFF,OFF,OFF,OFF);
delaySelbst(0.5);
Serial.println("F1 Gedruckt");
for (int d = 0 ; d < OffContactNumToPrint ; d++)
{
//Down ARROW
relay_SetStatus(OFF,OFF,OFF,ON);
delaySelbst(0.5); // the time for Relay start and stop
relay_SetStatus(OFF,OFF,OFF,OFF);
delaySelbst(0.5);
}
}
void setup() {
Serial.begin(9600);
relay_init();
}
void loop() {
while( TotalPrintingCount > ActualPrintingCount)
{
// put your main code here, to run repeatedly:
// read the state of the pushbutton value:
buttonState1 = digitalRead(buttonPin1);
// buttonState2 = digitalRead(buttonPin2);
// check if the pushbutton is pressed. If it is, the buttonState is HIGH:
for (int j=0 ; j < 10 ; j++)
{
delay(100);
if (buttonState1){
Serial.println("Button gedruckt");
Siebdruck();}
else
relay_init();
break;
}
}
}