└── PROCESSOR COADING /PROCESSOR COADING: -------------------------------------------------------------------------------- 1 | const int buttonPin = 2; // Button pin 2 | const int relayPin = 7; // Relay control pin 3 | const int engineSimulatorPin = 13; // LED to simulate engine status 4 | 5 | // Variables to store the state of the engine 6 | boolean engineRunning = false; 7 | 8 | void setup() { 9 | // Initialize the button pin as an input 10 | pinMode(buttonPin, INPUT_PULLUP); 11 | 12 | // Initialize the relay pin as an output 13 | pinMode(relayPin, OUTPUT); 14 | 15 | // Initialize the engine simulator LED pin as an output 16 | pinMode(engineSimulatorPin, OUTPUT); 17 | 18 | // By default, the engine is off 19 | digitalWrite(relayPin, LOW); 20 | digitalWrite(engineSimulatorPin, LOW); 21 | 22 | // Start with the engine locked 23 | lockEngine(); 24 | } 25 | 26 | void loop() { 27 | // Read the state of the button 28 | int buttonState = digitalRead(buttonPin); 29 | 30 | // Check if the button is pressed (LOW) 31 | if (buttonState == LOW) { 32 | if (engineRunning) { 33 | // If the engine is running, turn it off (lock the engine) 34 | lockEngine(); 35 | } else { 36 | // If the engine is off, start it (unlock the engine) 37 | unlockEngine(); 38 | } 39 | // Delay to debounce the button 40 | delay(1000); 41 | } 42 | } 43 | 44 | // Function to lock the engine 45 | void lockEngine() { 46 | digitalWrite(relayPin, LOW); // Turn off the relay 47 | digitalWrite(engineSimulatorPin, LOW); // Turn off the engine simulator LED 48 | engineRunning = false; 49 | Serial.println("Engine locked."); 50 | } 51 | 52 | // Function to unlock the engine 53 | void unlockEngine() { 54 | digitalWrite(relayPin, HIGH); // Turn on the relay 55 | digitalWrite(engineSimulatorPin, HIGH); // Turn on the engine simulator LED 56 | engineRunning = true; 57 | Serial.println("Engine unlocked."); 58 | } 59 | //This code sets up a simple engine locking system using an Arduino. 60 | --------------------------------------------------------------------------------