Advertisement
pleasedontcode

Intersection Control rev_01

Feb 21st, 2024
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /********* Pleasedontcode.com **********
  2.  
  3.     Pleasedontcode thanks you for automatic code generation! Enjoy your code!
  4.  
  5.     - Terms and Conditions:
  6.     You have a non-exclusive, revocable, worldwide, royalty-free license
  7.     for personal and commercial use. Attribution is optional; modifications
  8.     are allowed, but you're responsible for code maintenance. We're not
  9.     liable for any loss or damage. For full terms,
  10.     please visit pleasedontcode.com/termsandconditions.
  11.  
  12.     - Project: Intersection Control
  13.     - Source Code compiled for: Arduino Uno
  14.     - Source Code created on: 2024-02-21 08:32:29
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* - Implement a system that manages an intersection */
  21.     /* with two traffic lights, coming from two */
  22.     /* perpendicular roads, so as to properly manage the */
  23.     /* movement of vehicles, realizing them through LEDs. */
  24.     /* - Next, insert a button, for pedestrian crossing */
  25.     /* on call: */
  26. /****** END SYSTEM REQUIREMENTS *****/
  27.  
  28. /****** DEFINITION OF LIBRARIES *****/
  29. #include <EasyButton.h>    // https://github.com/evert-arias/EasyButton
  30.  
  31. /****** SYSTEM REQUIREMENTS *****/
  32. /****** SYSTEM REQUIREMENT 1 *****/
  33. /* - Implement a system that manages an intersection */
  34. /* with two traffic lights, coming from two */
  35. /* perpendicular roads, so as to properly manage the */
  36. /* movement of vehicles, realizing them through LEDs. */
  37. /* - Next, insert a button, for pedestrian crossing */
  38. /* on call: */
  39. /****** END SYSTEM REQUIREMENTS *****/
  40.  
  41. /****** FUNCTION PROTOTYPES *****/
  42. void setup(void);
  43. void loop(void);
  44. void updateOutputs(void);
  45.  
  46. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  47. const uint8_t button_PushButton_PIN_D2 = 2;
  48.  
  49. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  50. const uint8_t l1_Red_LED_PIN_D3 = 3;
  51. const uint8_t l2_Yellow_LED_PIN_D4 = 4;
  52. const uint8_t l3_Green_LED_PIN_D5 = 5;
  53.  
  54. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  55. /***** used to store raw data *****/
  56. bool l1_Red_LED_PIN_D3_rawData = 0;
  57. bool l2_Yellow_LED_PIN_D4_rawData = 0;
  58. bool l3_Green_LED_PIN_D5_rawData = 0;
  59.  
  60. /****** DEFINITION OF LIBRARIES CLASS INSTANCES *****/
  61. // Instance of the button.
  62. EasyButton button(button_PushButton_PIN_D2);
  63.  
  64. void setup(void)
  65. {
  66.     pinMode(button_PushButton_PIN_D2, INPUT_PULLUP);
  67.  
  68.     pinMode(l1_Red_LED_PIN_D3, OUTPUT);
  69.     pinMode(l2_Yellow_LED_PIN_D4, OUTPUT);
  70.     pinMode(l3_Green_LED_PIN_D5, OUTPUT);
  71.  
  72.     // Initialize the button.
  73.     button.begin();
  74. }
  75.  
  76. void loop(void)
  77. {
  78.     updateOutputs(); // Refresh output data
  79.     button.read();  // Read button status
  80.  
  81.     // Check if button is pressed and perform actions
  82.     if (button.isPressed())
  83.     {
  84.         // Perform actions when button is pressed
  85.         // This is where you can implement the pedestrian crossing logic
  86.         l1_Red_LED_PIN_D3_rawData = 1;
  87.         l2_Yellow_LED_PIN_D4_rawData = 1;
  88.         l3_Green_LED_PIN_D5_rawData = 0;
  89.     }
  90.     else
  91.     {
  92.         // Default traffic light behavior
  93.         l1_Red_LED_PIN_D3_rawData = 0;
  94.         l2_Yellow_LED_PIN_D4_rawData = 0;
  95.         l3_Green_LED_PIN_D5_rawData = 1;
  96.     }
  97.  
  98.     // Delay for stability
  99.     delay(100);
  100. }
  101.  
  102. void updateOutputs()
  103. {
  104.     digitalWrite(l1_Red_LED_PIN_D3, l1_Red_LED_PIN_D3_rawData);
  105.     digitalWrite(l2_Yellow_LED_PIN_D4, l2_Yellow_LED_PIN_D4_rawData);
  106.     digitalWrite(l3_Green_LED_PIN_D5, l3_Green_LED_PIN_D5_rawData);
  107. }
  108.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement