/********* Pleasedontcode.com ********** Pleasedontcode thanks you for automatic code generation! Enjoy your code! - Terms and Conditions: You have a non-exclusive, revocable, worldwide, royalty-free license for personal and commercial use. Attribution is optional; modifications are allowed, but you're responsible for code maintenance. We're not liable for any loss or damage. For full terms, please visit pleasedontcode.com/termsandconditions. - Project: Intersection Control - Source Code compiled for: Arduino Uno - Source Code created on: 2024-02-21 08:32:29 ********* Pleasedontcode.com **********/ /****** SYSTEM REQUIREMENTS *****/ /****** SYSTEM REQUIREMENT 1 *****/ /* - Implement a system that manages an intersection */ /* with two traffic lights, coming from two */ /* perpendicular roads, so as to properly manage the */ /* movement of vehicles, realizing them through LEDs. */ /* - Next, insert a button, for pedestrian crossing */ /* on call: */ /****** END SYSTEM REQUIREMENTS *****/ /****** DEFINITION OF LIBRARIES *****/ #include // https://github.com/evert-arias/EasyButton /****** SYSTEM REQUIREMENTS *****/ /****** SYSTEM REQUIREMENT 1 *****/ /* - Implement a system that manages an intersection */ /* with two traffic lights, coming from two */ /* perpendicular roads, so as to properly manage the */ /* movement of vehicles, realizing them through LEDs. */ /* - Next, insert a button, for pedestrian crossing */ /* on call: */ /****** END SYSTEM REQUIREMENTS *****/ /****** FUNCTION PROTOTYPES *****/ void setup(void); void loop(void); void updateOutputs(void); /***** DEFINITION OF DIGITAL INPUT PINS *****/ const uint8_t button_PushButton_PIN_D2 = 2; /***** DEFINITION OF DIGITAL OUTPUT PINS *****/ const uint8_t l1_Red_LED_PIN_D3 = 3; const uint8_t l2_Yellow_LED_PIN_D4 = 4; const uint8_t l3_Green_LED_PIN_D5 = 5; /***** DEFINITION OF OUTPUT RAW VARIABLES *****/ /***** used to store raw data *****/ bool l1_Red_LED_PIN_D3_rawData = 0; bool l2_Yellow_LED_PIN_D4_rawData = 0; bool l3_Green_LED_PIN_D5_rawData = 0; /****** DEFINITION OF LIBRARIES CLASS INSTANCES *****/ // Instance of the button. EasyButton button(button_PushButton_PIN_D2); void setup(void) { pinMode(button_PushButton_PIN_D2, INPUT_PULLUP); pinMode(l1_Red_LED_PIN_D3, OUTPUT); pinMode(l2_Yellow_LED_PIN_D4, OUTPUT); pinMode(l3_Green_LED_PIN_D5, OUTPUT); // Initialize the button. button.begin(); } void loop(void) { updateOutputs(); // Refresh output data button.read(); // Read button status // Check if button is pressed and perform actions if (button.isPressed()) { // Perform actions when button is pressed // This is where you can implement the pedestrian crossing logic l1_Red_LED_PIN_D3_rawData = 1; l2_Yellow_LED_PIN_D4_rawData = 1; l3_Green_LED_PIN_D5_rawData = 0; } else { // Default traffic light behavior l1_Red_LED_PIN_D3_rawData = 0; l2_Yellow_LED_PIN_D4_rawData = 0; l3_Green_LED_PIN_D5_rawData = 1; } // Delay for stability delay(100); } void updateOutputs() { digitalWrite(l1_Red_LED_PIN_D3, l1_Red_LED_PIN_D3_rawData); digitalWrite(l2_Yellow_LED_PIN_D4, l2_Yellow_LED_PIN_D4_rawData); digitalWrite(l3_Green_LED_PIN_D5, l3_Green_LED_PIN_D5_rawData); }