Advertisement
pleasedontcode

Traffic Control rev_01

Feb 10th, 2024
42
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: Traffic Control
  13.     - Source Code compiled for: Arduino Uno
  14.     - Source Code created on: 2024-02-10 07:15:14
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* turn on and off traffic lights when pressing a */
  21.     /* button */
  22. /****** END SYSTEM REQUIREMENTS *****/
  23.  
  24. /****** DEFINITION OF LIBRARIES *****/
  25. #include <Arduino.h>
  26.  
  27. /****** SYSTEM REQUIREMENTS *****/
  28. /****** SYSTEM REQUIREMENT 1 *****/
  29.     /* turn on and off traffic lights when pressing a */
  30.     /* button */
  31. /****** END SYSTEM REQUIREMENTS *****/
  32.  
  33. /****** FUNCTION PROTOTYPES *****/
  34. void setup(void);
  35. void loop(void);
  36. void updateOutputs(void);
  37.  
  38. /***** DEFINITION OF DIGITAL INPUT/OUTPUT PINS *****/
  39. const uint8_t mybutton_PIN_D2 = 2;
  40. const uint8_t mybutton_LED_PIN_D3 = 3;
  41. const uint8_t mybutton_LED_PIN_D4 = 4;
  42.  
  43. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  44. bool mybutton_LED_PIN_D3_rawData = 0;
  45. bool mybutton_LED_PIN_D4_rawData = 0;
  46.  
  47. void setup(void)
  48. {
  49.   // put your setup code here, to run once:
  50.   pinMode(mybutton_PIN_D2, INPUT_PULLUP);
  51.   pinMode(mybutton_LED_PIN_D3, OUTPUT);
  52.   pinMode(mybutton_LED_PIN_D4, OUTPUT);
  53. }
  54.  
  55. void loop(void)
  56. {
  57.   // put your main code here, to run repeatedly:
  58.   if (digitalRead(mybutton_PIN_D2) == LOW)
  59.   {
  60.     mybutton_LED_PIN_D3_rawData = !mybutton_LED_PIN_D3_rawData; // Toggle the state of LED_PIN_D3
  61.     mybutton_LED_PIN_D4_rawData = !mybutton_LED_PIN_D4_rawData; // Toggle the state of LED_PIN_D4
  62.     delay(500); // Debounce delay
  63.   }
  64.  
  65.   updateOutputs(); // Refresh output data
  66. }
  67.  
  68. void updateOutputs()
  69. {
  70.   digitalWrite(mybutton_LED_PIN_D3, mybutton_LED_PIN_D3_rawData);
  71.   digitalWrite(mybutton_LED_PIN_D4, mybutton_LED_PIN_D4_rawData);
  72. }
  73.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement