/*SN230 Rev B Code by Paul and David Bradt based on these original codes: I arduino.cc/en/Tutorial/InputPullupSerial Simulation of an Arc welder By Steve Spence https://circuitcrush.com/arduino/2016/11/05/arduino-model-railroading-arc-welder.html */ unsigned long start_Torch_Millis, start_Arc_Millis, currentMillis; const unsigned long arc_period = 12280; const unsigned long torch_period = 46750; bool sensorVal2 = false, sensorVal3 = false; //Rev E simulating arc welder with White LED // More rapid flicker void setup() { //start serial connection Serial.begin(9600); pinMode(2, INPUT_PULLUP); //configure pin 3 as an input and enable the internal pull-up resistor pinMode(3, INPUT_PULLUP); pinMode(7, OUTPUT); pinMode(8, OUTPUT); start_Arc_Millis = millis(); start_Torch_Millis = millis(); } void loop() { currentMillis = millis(); if (digitalRead(3) == LOW && sensorVal3 == false) { sensorVal2 = true; Serial.println(3); } if (digitalRead(2) == LOW && sensorVal2 == false) { sensorVal3 = true; Serial.println(2); } //This section emulates the randomness of a cutting torch if (sensorVal2 == true && sensorVal3 == false) {//Cutting Torch Welder digitalWrite(7, HIGH); // set the Light on delay(55); //Delay for how long Light stay on digitalWrite(7, LOW); // set the Light off delay(9); //Delay For how long Light turn back on if ((currentMillis - start_Torch_Millis) >= torch_period) { sensorVal2 = false; digitalWrite(7, LOW); start_Torch_Millis = millis(); } } //This section emulates the randomness of an Arc Welder if (sensorVal3 == true && sensorVal2 == false) {//Arc Welder digitalWrite(8, HIGH); // set the LED on delay(55); //Delay for how long LED stay on digitalWrite(8, LOW); // set the LED off delay(9); //Delay For how long LED turn back on if ((currentMillis - start_Arc_Millis) >= arc_period) { sensorVal3 = false; digitalWrite(8, LOW); start_Arc_Millis = millis(); } } delay(10); }