bool CNCrunning = false; //This boolean function allows the program to keep track of whether the CNC machine is running, as a true or false value, and sets it to false at the beggining of the programme.
void setup() {
pinMode(2, OUTPUT); //Declares that digital pin 2 is an output pin. This will be used for LED A on the 7-segment display.
pinMode(3, OUTPUT); //Declares that digital pin 3 is an output pin. This will be used for LED B on the 7-segment display.
pinMode(4, OUTPUT); //Declares that digital pin 4 is an output pin. This will be used for LED C on the 7-segment display.
pinMode(5, OUTPUT); //Declares that digital pin 5 is an output pin. This will be used for LED D on the 7-segment display.
pinMode(6, OUTPUT); //Declares that digital pin 6 is an output pin. This will be used for LED E on the 7-segment display.
pinMode(7, OUTPUT); //Declares that digital pin 7 is an output pin. This will be used for LED F on the 7-segment display.
pinMode(8, OUTPUT); //Declares that digital pin 8 is an output pin. This will be used for LED G on the 7-segment display.
pinMode(9, OUTPUT); //Declares that digital pin 9 is an output pin. This will be used for LED B and C on the second 7-segment display.
pinMode(10, OUTPUT); //Declares that digital pin 10 is an output pin. This will be used to power and controll the DC motor.
pinMode(11, OUTPUT); //Declares that digital pin 11 is an output pin. This will be used to power and conroll the red lead of the RGB LED.
pinMode(12, OUTPUT); //Declares that digital pin 12 is an output pin. This will be used to power and conroll the green lead of the RGB LED.
pinMode(13, INPUT_PULLUP); //Declares that digital pin 12 is an input pullup pin, which uses the in built pullup resistor. This will be used to recieve the start button input.
}
void loop() {
//This section of the code checks if the start button in pin 13 has been pressed.
if (digitalRead(13) == LOW && !CNCrunning) { //This if statement asks if the input at pin 13 is low, and the CNC machine is not running.
CNCrunning = true; //When the above is true, this line sets the bool bunction CNCrunning to true.
}
if (CNCrunning) { //This if statement will run when the bool CNCrunning is true, and activates the sequence of the CNC machine operation.
digitalWrite(10, HIGH); //This sets the output at pin 10, which is connected to the DC motor, to high, turning the DC motor on.
digitalWrite(11, HIGH); //This sets the output at pin 11, which is connected to the red lead of the RGB LED, to high, making the LED iluminate red, indicating that the door can't be opened.
digitalWrite(12, LOW); //This sets the output at pin 12, which is connected to the green lead of the RGB LED, to high, making sure the LED does not iluminate green.
digitalWrite(2, HIGH); //This sets the output at pin 2, to high, the correct setting for LED A when displaying "0" on a 7-segment display.
digitalWrite(3, HIGH); //This sets the output at pin 3, to high, the correct setting for LED B when displaying "0" on a 7-segment display.
digitalWrite(4, HIGH); //This sets the output at pin 4, to high, the correct setting for LED C when displaying "0" on a 7-segment display.
digitalWrite(5, HIGH); //This sets the output at pin 5, to high, the correct setting for LED D when displaying "0" on a 7-segment display.
digitalWrite(6, HIGH); //This sets the output at pin 6, to high, the correct setting for LED E when displaying "0" on a 7-segment display.
digitalWrite(7, HIGH); //This sets the output at pin 7, to high, the correct setting for LED F when displaying "0" on a 7-segment display.
digitalWrite(8, LOW); //This sets the output at pin 8, to low, the correct setting for LED G when displaying "0" on a 7-segment display.
digitalWrite(9, HIGH); //This sets the output at pin 9, to high, the correct setting for LED B and C when displaying "1" on a 7-segment display.
delay(1000); //The delay function causes the programme to wait 1 second, or 1000 milliseconds, before execurting the next line.
digitalWrite(2, HIGH); //This sets the output at pin 2, to high, the correct setting for LED A when displaying "9" on a 7-segment display.
digitalWrite(3, HIGH); //This sets the output at pin 3, to high, the correct setting for LED B when displaying "9" on a 7-segment display.
digitalWrite(4, HIGH); //This sets the output at pin 4, to high, the correct setting for LED C when displaying "9" on a 7-segment display.
digitalWrite(5, LOW); //This sets the output at pin 5, to low, the correct setting for LED D when displaying "9" on a 7-segment display.
digitalWrite(6, LOW); //This sets the output at pin 6, to low, the correct setting for LED E when displaying "9" on a 7-segment display.
digitalWrite(7, HIGH); //This sets the output at pin 7, to high, the correct setting for LED F when displaying "9" on a 7-segment display.
digitalWrite(8, HIGH); //This sets the output at pin 8, to high, the correct setting for LED G when displaying "9" on a 7-segment display.
digitalWrite(9, LOW); //This sets the output at pin 9, to low, as the second 7-segment display is not used when displaying "9".
delay(1000); //The delay function causes the programme to wait 1 second, or 1000 milliseconds, before execurting the next line.
digitalWrite(2, HIGH); //This sets the output at pin 2, to high, the correct setting for LED A when displaying "8" on a 7-segment display.
digitalWrite(3, HIGH); //This sets the output at pin 3, to high, the correct setting for LED B when displaying "8" on a 7-segment display.
digitalWrite(4, HIGH); //This sets the output at pin 4, to high, the correct setting for LED C when displaying "8" on a 7-segment display.
digitalWrite(5, HIGH); //This sets the output at pin 5, to high, the correct setting for LED C when displaying "8" on a 7-segment display.
digitalWrite(6, HIGH); //This sets the output at pin 6, to high, the correct setting for LED C when displaying "8" on a 7-segment display.
digitalWrite(7, HIGH); //This sets the output at pin 7, to high, the correct setting for LED C when displaying "8" on a 7-segment display.
digitalWrite(8, HIGH); //This sets the output at pin 8, to high, the correct setting for LED C when displaying "8" on a 7-segment display.
digitalWrite(9, LOW); //This sets the output at pin 9, to low, as the second 7-segment display is not used when displaying "8".
delay(1000); //The delay function causes the programme to wait 1 second, or 1000 milliseconds, before execurting the next line.
digitalWrite(2, HIGH); //This sets the output at pin 2, to high, the correct setting for LED A when displaying "7" on a 7-segment display.
digitalWrite(3, HIGH); //This sets the output at pin 3, to high, the correct setting for LED B when displaying "7" on a 7-segment display.
digitalWrite(4, HIGH); //This sets the output at pin 4, to high, the correct setting for LED C when displaying "7" on a 7-segment display.
digitalWrite(5, LOW); //This sets the output at pin 5, to low, the correct setting for LED D when displaying "7" on a 7-segment display.
digitalWrite(6, LOW); //This sets the output at pin 6, to low, the correct setting for LED E when displaying "7" on a 7-segment display.
digitalWrite(7, LOW); //This sets the output at pin 7, to low, the correct setting for LED F when displaying "7" on a 7-segment display.
digitalWrite(8, LOW); //This sets the output at pin 8, to low, the correct setting for LED G when displaying "7" on a 7-segment display.
digitalWrite(9, LOW); //This sets the output at pin 9, to low, as the second 7-segment display is not used when displaying "7".
delay(1000); //The delay function causes the programme to wait 1 second, or 1000 milliseconds, before execurting the next line.
digitalWrite(2, HIGH); //This sets the output at pin 2, to high, the correct setting for LED A when displaying "6" on a 7-segment display.
digitalWrite(3, LOW); //This sets the output at pin 3, to low, the correct setting for LED B when displaying "6" on a 7-segment display.
digitalWrite(4, HIGH); //This sets the output at pin 4, to high, the correct setting for LED C when displaying "6" on a 7-segment display.
digitalWrite(5, HIGH); //This sets the output at pin 5, to high, the correct setting for LED D when displaying "6" on a 7-segment display.
digitalWrite(6, HIGH); //This sets the output at pin 6, to high, the correct setting for LED E when displaying "6" on a 7-segment display.
digitalWrite(7, HIGH); //This sets the output at pin 7, to high, the correct setting for LED F when displaying "6" on a 7-segment display.
digitalWrite(8, HIGH); //This sets the output at pin 8, to high, the correct setting for LED G when displaying "6" on a 7-segment display.
digitalWrite(9, LOW); //This sets the output at pin 9, to low, as the second 7-segment display is not used when displaying "6".
delay(1000); //The delay function causes the programme to wait 1 second, or 1000 milliseconds, before execurting the next line.
digitalWrite(2, HIGH); //This sets the output at pin 2, to high, the correct setting for LED A when displaying "5" on a 7-segment display.
digitalWrite(3, LOW); //This sets the output at pin 3, to low, the correct setting for LED B when displaying "5" on a 7-segment display.
digitalWrite(4, HIGH); //This sets the output at pin 4, to high, the correct setting for LED C when displaying "5" on a 7-segment display.
digitalWrite(5, HIGH); //This sets the output at pin 5, to high, the correct setting for LED C when displaying "5" on a 7-segment display.
digitalWrite(6, LOW); //This sets the output at pin 6, to low, the correct setting for LED E when displaying "5" on a 7-segment display.
digitalWrite(7, HIGH); //This sets the output at pin 7, to high, the correct setting for LED C when displaying "5" on a 7-segment display.
digitalWrite(8, HIGH); //This sets the output at pin 8, to high, the correct setting for LED C when displaying "5" on a 7-segment display.
digitalWrite(9, LOW); //This sets the output at pin 9, to low, as the second 7-segment display is not used when displaying "5".
delay(1000); //The delay function causes the programme to wait 1 second, or 1000 milliseconds, before execurting the next line.
digitalWrite(2, LOW); //This sets the output at pin 2, to low, the correct setting for LED A when displaying "4" on a 7-segment display.
digitalWrite(3, HIGH); //This sets the output at pin 3, to high, the correct setting for LED B when displaying "4" on a 7-segment display.
digitalWrite(4, HIGH); //This sets the output at pin 4, to high, the correct setting for LED C when displaying "4" on a 7-segment display.
digitalWrite(5, LOW); //This sets the output at pin 5, to low, the correct setting for LED D when displaying "4" on a 7-segment display.
digitalWrite(6, LOW); //This sets the output at pin 6, to low, the correct setting for LED E when displaying "4" on a 7-segment display.
digitalWrite(7, HIGH); //This sets the output at pin 7, to high, the correct setting for LED C when displaying "4" on a 7-segment display.
digitalWrite(8, HIGH); //This sets the output at pin 8, to high, the correct setting for LED C when displaying "4" on a 7-segment display.
digitalWrite(9, LOW); //This sets the output at pin 9, to low, as the second 7-segment display is not used when displaying "4".
delay(1000); //The delay function causes the programme to wait 1 second, or 1000 milliseconds, before execurting the next line.
digitalWrite(2, HIGH); //This sets the output at pin 2, to high, the correct setting for LED A when displaying "3" on a 7-segment display.
digitalWrite(3, HIGH); //This sets the output at pin 3, to high, the correct setting for LED B when displaying "3" on a 7-segment display.
digitalWrite(4, HIGH); //This sets the output at pin 4, to high, the correct setting for LED C when displaying "3" on a 7-segment display.
digitalWrite(5, HIGH); //This sets the output at pin 5, to high, the correct setting for LED C when displaying "3" on a 7-segment display.
digitalWrite(6, LOW); //This sets the output at pin 6, to low, the correct setting for LED E when displaying "3" on a 7-segment display.
digitalWrite(7, LOW); //This sets the output at pin 7, to low, the correct setting for LED F when displaying "3" on a 7-segment display.
digitalWrite(8, HIGH); //This sets the output at pin 8, to high, the correct setting for LED C when displaying "3" on a 7-segment display.
digitalWrite(9, LOW); //This sets the output at pin 9, to low, as the second 7-segment display is not used when displaying "3".
delay(1000); //The delay function causes the programme to wait 1 second, or 1000 milliseconds, before execurting the next line.
digitalWrite(2, HIGH); //This sets the output at pin 2, to high, the correct setting for LED A when displaying "2" on a 7-segment display.
digitalWrite(3, HIGH); //This sets the output at pin 3, to high, the correct setting for LED B when displaying "2" on a 7-segment display.
digitalWrite(4, LOW); //This sets the output at pin 4, to low, the correct setting for LED C when displaying "2" on a 7-segment display.
digitalWrite(5, HIGH); //This sets the output at pin 5, to high, the correct setting for LED C when displaying "2" on a 7-segment display.
digitalWrite(6, HIGH); //This sets the output at pin 6, to high, the correct setting for LED C when displaying "2" on a 7-segment display.
digitalWrite(7, LOW); //This sets the output at pin 7, to low, the correct setting for LED F when displaying "2" on a 7-segment display.
digitalWrite(8, HIGH); //This sets the output at pin 8, to high, the correct setting for LED C when displaying "2" on a 7-segment display.
digitalWrite(9, LOW); //This sets the output at pin 9, to low, as the second 7-segment display is not used when displaying "2".
delay(1000); //The delay function causes the programme to wait 1 second, or 1000 milliseconds, before execurting the next line.
digitalWrite(2, LOW); //This sets the output at pin 2, to low, the correct setting for LED A when displaying "1" on a 7-segment display.
digitalWrite(3, HIGH); //This sets the output at pin 3, to high, the correct setting for LED B when displaying "1" on a 7-segment display.
digitalWrite(4, HIGH); //This sets the output at pin 4, to high, the correct setting for LED C when displaying "1" on a 7-segment display.
digitalWrite(5, LOW); //This sets the output at pin 5, to low, the correct setting for LED D when displaying "1" on a 7-segment display.
digitalWrite(6, LOW); //This sets the output at pin 6, to low, the correct setting for LED E when displaying "1" on a 7-segment display.
digitalWrite(7, LOW); //This sets the output at pin 7, to low, the correct setting for LED F when displaying "1" on a 7-segment display.
digitalWrite(8, LOW); //This sets the output at pin 8, to low, the correct setting for LED G when displaying "1" on a 7-segment display.
digitalWrite(9, LOW); //This sets the output at pin 9, to low, as the second 7-segment display is not used when displaying "1".
delay(1000); //The delay function causes the programme to wait 1 second, or 1000 milliseconds, before execurting the next line.
digitalWrite(2, HIGH); //This sets the output at pin 2, to high, the correct setting for LED A when displaying "0" on a 7-segment display.
digitalWrite(3, HIGH); //This sets the output at pin 3, to high, the correct setting for LED B when displaying "0" on a 7-segment display.
digitalWrite(4, HIGH); //This sets the output at pin 4, to high, the correct setting for LED C when displaying "0" on a 7-segment display.
digitalWrite(5, HIGH); //This sets the output at pin 5, to high, the correct setting for LED D when displaying "0" on a 7-segment display.
digitalWrite(6, HIGH); //This sets the output at pin 6, to high, the correct setting for LED E when displaying "0" on a 7-segment display.
digitalWrite(7, HIGH); //This sets the output at pin 7, to high, the correct setting for LED F when displaying "0" on a 7-segment display.
digitalWrite(8, LOW); //This sets the output at pin 8, to low, the correct setting for LED G when displaying "0" on a 7-segment display.
digitalWrite(9, LOW); //This sets the output at pin 9, to low, as the second 7-segment display is not used when displaying "0".
digitalWrite(10, LOW); //This sets the output at pin 10, which is connected to the DC motor, to low, turning the DC motor off.
digitalWrite(11, HIGH); //This sets the output at pin 11, which is connected to the red lead of the RGB LED, to high, making the LED iluminate red, indicating that the door can't be opened.
digitalWrite(12, LOW); //This sets the output at pin 12, which is connected to the green lead of the RGB LED, to high, making sure the LED does not iluminate green.
delay(1000); //The delay function causes the programme to wait 1 second, or 1000 milliseconds, before execurting the next line.
digitalWrite(2, HIGH); //This sets the output at pin 2, to high, the correct setting for LED A when displaying "5" on a 7-segment display.
digitalWrite(3, LOW); //This sets the output at pin 3, to low, the correct setting for LED B when displaying "5" on a 7-segment display.
digitalWrite(4, HIGH); //This sets the output at pin 4, to high, the correct setting for LED C when displaying "5" on a 7-segment display.
digitalWrite(5, HIGH); //This sets the output at pin 5, to high, the correct setting for LED D when displaying "5" on a 7-segment display.
digitalWrite(6, LOW); //This sets the output at pin 6, to low, the correct setting for LED E when displaying "5" on a 7-segment display.
digitalWrite(7, HIGH); //This sets the output at pin 7, to high, the correct setting for LED F when displaying "5" on a 7-segment display.
digitalWrite(8, HIGH); //This sets the output at pin 8, to high, the correct setting for LED G when displaying "5" on a 7-segment display.
digitalWrite(9, LOW); //This sets the output at pin 9, to low, as the second 7-segment display is not used when displaying "5".
delay(1000); //The delay function causes the programme to wait 1 second, or 1000 milliseconds, before execurting the next line.
digitalWrite(2, LOW); //This sets the output at pin 2, to low, the correct setting for LED A when displaying "4" on a 7-segment display.
digitalWrite(3, HIGH); //This sets the output at pin 3, to high, the correct setting for LED B when displaying "4" on a 7-segment display.
digitalWrite(4, HIGH); //This sets the output at pin 4, to high, the correct setting for LED C when displaying "4" on a 7-segment display.
digitalWrite(5, LOW); //This sets the output at pin 5, to low, the correct setting for LED D when displaying "4" on a 7-segment display.
digitalWrite(6, LOW); //This sets the output at pin 6, to low, the correct setting for LED E when displaying "4" on a 7-segment display.
digitalWrite(7, HIGH); //This sets the output at pin 7, to high, the correct setting for LED F when displaying "4" on a 7-segment display.
digitalWrite(8, HIGH); //This sets the output at pin 8, to high, the correct setting for LED G when displaying "4" on a 7-segment display.
digitalWrite(9, LOW); //This sets the output at pin 9, to low, as the second 7-segment display is not used when displaying "4".
delay(1000); //The delay function causes the programme to wait 1 second, or 1000 milliseconds, before execurting the next line.
digitalWrite(2, HIGH); //This sets the output at pin 2, to high, the correct setting for LED A when displaying "3" on a 7-segment display.
digitalWrite(3, HIGH); //This sets the output at pin 3, to high, the correct setting for LED B when displaying "3" on a 7-segment display.
digitalWrite(4, HIGH); //This sets the output at pin 4, to high, the correct setting for LED C when displaying "3" on a 7-segment display.
digitalWrite(5, HIGH); //This sets the output at pin 5, to high, the correct setting for LED D when displaying "3" on a 7-segment display.
digitalWrite(6, LOW); //This sets the output at pin 6, to low, the correct setting for LED E when displaying "3" on a 7-segment display.
digitalWrite(7, LOW); //This sets the output at pin 7, to low, the correct setting for LED F when displaying "3" on a 7-segment display.
digitalWrite(8, HIGH); //This sets the output at pin 6, to high, the correct setting for LED G when displaying "3" on a 7-segment display.
digitalWrite(9, LOW); //This sets the output at pin 9, to low, as the second 7-segment display is not used when displaying "3".
delay(1000); //The delay function causes the programme to wait 1 second, or 1000 milliseconds, before execurting the next line.
digitalWrite(2, HIGH); //This sets the output at pin 2, to high, the correct setting for LED A when displaying "2" on a 7-segment display.
digitalWrite(3, HIGH); //This sets the output at pin 3, to high, the correct setting for LED B when displaying "2" on a 7-segment display.
digitalWrite(4, LOW); //This sets the output at pin 4, to low, the correct setting for LED C when displaying "2" on a 7-segment display.
digitalWrite(5, HIGH); //This sets the output at pin 5, to high, the correct setting for LED C when displaying "2" on a 7-segment display.
digitalWrite(6, HIGH); //This sets the output at pin 6, to high, the correct setting for LED C when displaying "2" on a 7-segment display.
digitalWrite(7, LOW); //This sets the output at pin 7, to low, the correct setting for LED F when displaying "2" on a 7-segment display.
digitalWrite(8, HIGH); //This sets the output at pin 8, to high, the correct setting for LED C when displaying "2" on a 7-segment display.
digitalWrite(9, LOW); //This sets the output at pin 9, to low, as the second 7-segment display is not used when displaying "2".
delay(1000); //The delay function causes the programme to wait 1 second, or 1000 milliseconds, before execurting the next line.
digitalWrite(2, LOW); //This sets the output at pin 2, to low, the correct setting for LED A when displaying "1" on a 7-segment display.
digitalWrite(3, HIGH); //This sets the output at pin 3, to high, the correct setting for LED B when displaying "1" on a 7-segment display.
digitalWrite(4, HIGH); //This sets the output at pin 4, to high, the correct setting for LED C when displaying "1" on a 7-segment display.
digitalWrite(5, LOW); //This sets the output at pin 5, to low, the correct setting for LED D when displaying "1" on a 7-segment display.
digitalWrite(6, LOW); //This sets the output at pin 6, to low, the correct setting for LED E when displaying "1" on a 7-segment display.
digitalWrite(7, LOW); //This sets the output at pin 7, to low, the correct setting for LED F when displaying "1" on a 7-segment display.
digitalWrite(8, LOW); //This sets the output at pin 8, to low, the correct setting for LED G when displaying "1" on a 7-segment display.
digitalWrite(9, LOW); //This sets the output at pin 9, to low, as the second 7-segment display is not used when displaying "1".
delay(1000); //The delay function causes the programme to wait 1 second, or 1000 milliseconds, before execurting the next line.
digitalWrite(2, HIGH); //This sets the output at pin 2, to high, the correct setting for LED A when displaying "0" on a 7-segment display.
digitalWrite(3, HIGH); //This sets the output at pin 3, to high, the correct setting for LED B when displaying "0" on a 7-segment display.
digitalWrite(4, HIGH); //This sets the output at pin 4, to high, the correct setting for LED C when displaying "0" on a 7-segment display.
digitalWrite(5, HIGH); //This sets the output at pin 5, to high, the correct setting for LED D when displaying "0" on a 7-segment display.
digitalWrite(6, HIGH); //This sets the output at pin 6, to high, the correct setting for LED E when displaying "0" on a 7-segment display.
digitalWrite(7, HIGH); //This sets the output at pin 7, to high, the correct setting for LED F when displaying "0" on a 7-segment display.
digitalWrite(8, LOW); //This sets the output at pin 8, to low, the correct setting for LED G when displaying "0" on a 7-segment display.
digitalWrite(9, LOW); //This sets the output at pin 9, to low, as the second 7-segment display is not used when displaying "0".
digitalWrite(11, LOW); //This sets the output at pin 11 to low, turning off the red light from the RGB LED.
digitalWrite(12, HIGH); //This sets the output at pin 12 to high, turning on the green light from the RGB LED, indicating that it is safe to open the door.
} else { //This else statement is an alternative to the if statement at the begining of the programme, and it means that if the start button is not pressed, all outpputs will be low, meaning everything is off.
digitalWrite(10, LOW);
digitalWrite(11, LOW);
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
digitalWrite(6, LOW);
digitalWrite(7, LOW);
digitalWrite(8, LOW);
digitalWrite(9, LOW);
}
CNCrunning = false; //This sets the bool function CNCrunning back to false when the sequence has been completed, meaning the machine can be run again if the start button is re-pressed.
}