int powerUp = 2; //RED PB
#define motorCtrl 3 //Red LED
#define lightCtrl 4 //Green LED
#define doorCtrl 5 //Blue LED
#define buzzerCtrl 6 //Yellow LED
#define punchCtrl 7 //Blue PB
#define punchMotor 8
int latchState = LOW;
int currentState = LOW;
int lastState = LOW;
int punch = LOW;
void setup()
{
//defining pinmodes of pins
pinMode(powerUp, INPUT); //main control switch
pinMode(motorCtrl, OUTPUT); //motor control circuit ouput
pinMode(lightCtrl, OUTPUT); //workarea lighting
pinMode(doorCtrl, OUTPUT); //door interlock control
pinMode(buzzerCtrl, OUTPUT); //buzzer to indicate ready state of punching m/c
pinMode(punchCtrl, INPUT); //PB to operate punching m/c
pinMode(punchMotor, OUTPUT); //Light blue LED to indicate the punching motor
//initializing the serial monitor @ 9600 baudrate
Serial.begin(9600);
attachInterrupt(digitalPinToInterrupt(powerUp), power, CHANGE);
}
void loop() {
// put your main code here, to run repeatedly:
//switching ON devices when PB/latch State is ON
if (latchState == HIGH)
{
digitalWrite(lightCtrl, HIGH); //green
delay(150);
digitalWrite(doorCtrl, HIGH); //blue
delay(150);
digitalWrite(motorCtrl, HIGH); //red
delay(150);
digitalWrite(buzzerCtrl, HIGH); //yellow
punch = digitalRead(punchCtrl);
if (punch == HIGH)
{
digitalWrite(punchMotor, HIGH);
delay(5000);
}
else
{
digitalWrite(punchMotor, LOW);
}
}
//switching OFF devices when PB/latch State is OFF
else if (latchState == LOW)
{
digitalWrite(punchMotor, LOW);
digitalWrite(buzzerCtrl, LOW); //yellow
delay(300);
digitalWrite(motorCtrl, LOW); //red
delay(300);
digitalWrite(doorCtrl, LOW); //blue
delay(300);
digitalWrite(lightCtrl, LOW); //green
}
Serial.print("latch = ");
Serial.println(latchState);
Serial.print("punch = ");
Serial.println(punch);
}
void power(void)
{
latchState = !latchState;
}