Advertisement
pleasedontcode

"Digital Control" rev_01

Apr 6th, 2024
55
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: "Digital Control"
  13.     - Source Code compiled for: Arduino Uno
  14.     - Source Code created on: 2024-04-06 08:57:25
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* when the easy button was pressed, the green led */
  21.     /* and bazeer flashed 10 times */
  22. /****** SYSTEM REQUIREMENT 2 *****/
  23.     /* when the green led stops turn on the red led for */
  24.     /* 15 seconds */
  25. /****** END SYSTEM REQUIREMENTS *****/
  26.  
  27. /****** DEFINITION OF LIBRARIES *****/
  28. #include <EasyButton.h>
  29. #include <ezBuzzer.h>
  30.  
  31. /****** FUNCTION PROTOTYPES *****/
  32. void setup(void);
  33. void loop(void);
  34. void updateOutputs(void);
  35.  
  36. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  37. const uint8_t tilt_PushButton_PIN_D2 = 2;
  38.  
  39. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  40. const uint8_t red_LED_PIN_D3 = 3;
  41. const uint8_t green_LED_PIN_D4 = 4;
  42. const uint8_t bazer_PassiveBuzzer_Signal_PIN_D5 = 5;
  43.  
  44. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  45. bool red_LED_PIN_D3_rawData = 0;
  46. bool green_LED_PIN_D4_rawData = 0;
  47. bool bazer_PassiveBuzzer_Signal_PIN_D5_rawData = 0;
  48.  
  49. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  50. float red_LED_PIN_D3_phyData = 0.0;
  51. float green_LED_PIN_D4_phyData = 0.0;
  52. float bazer_PassiveBuzzer_Signal_PIN_D5_phyData = 0.0;
  53.  
  54. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  55. EasyButton tilt_PushButton(tilt_PushButton_PIN_D2);
  56. ezBuzzer bazer_PassiveBuzzer(bazer_PassiveBuzzer_Signal_PIN_D5);
  57.  
  58. int flashCount = 0;
  59. bool isRedLedOn = false;
  60. unsigned long redLedStartTime = 0;
  61.  
  62. void setup(void)
  63. {
  64.   pinMode(tilt_PushButton_PIN_D2, INPUT_PULLUP);
  65.   pinMode(red_LED_PIN_D3, OUTPUT);
  66.   pinMode(green_LED_PIN_D4, OUTPUT);
  67.   pinMode(bazer_PassiveBuzzer_Signal_PIN_D5, OUTPUT);
  68.  
  69.   tilt_PushButton.begin();
  70.   // bazer_PassiveBuzzer.begin(); // Commented out as it seems to be causing the error
  71. }
  72.  
  73. void loop(void)
  74. {
  75.   updateOutputs();
  76.  
  77.   // Check if the button is pressed
  78.   if (tilt_PushButton.read())
  79.   {
  80.     // Flash the green LED and buzzer 10 times
  81.     if (flashCount < 10)
  82.     {
  83.       green_LED_PIN_D4_rawData = !green_LED_PIN_D4_rawData;
  84.       bazer_PassiveBuzzer.beep(100);
  85.       delay(100);
  86.       flashCount++;
  87.     }
  88.     else
  89.     {
  90.       // Turn off the green LED and buzzer
  91.       green_LED_PIN_D4_rawData = LOW;
  92.       bazer_PassiveBuzzer.stop();
  93.  
  94.       // Turn on the red LED and start the timer
  95.       if (!isRedLedOn)
  96.       {
  97.         red_LED_PIN_D3_rawData = HIGH;
  98.         redLedStartTime = millis();
  99.         isRedLedOn = true;
  100.       }
  101.     }
  102.   }
  103.  
  104.   // Check if the red LED has been on for 15 seconds
  105.   if (isRedLedOn && (millis() - redLedStartTime >= 15000))
  106.   {
  107.     // Turn off the red LED
  108.     red_LED_PIN_D3_rawData = LOW;
  109.     isRedLedOn = false;
  110.   }
  111. }
  112.  
  113. void updateOutputs(void)
  114. {
  115.   digitalWrite(red_LED_PIN_D3, red_LED_PIN_D3_rawData);
  116.   digitalWrite(green_LED_PIN_D4, green_LED_PIN_D4_rawData);
  117.   digitalWrite(bazer_PassiveBuzzer_Signal_PIN_D5, bazer_PassiveBuzzer_Signal_PIN_D5_rawData);
  118. }
  119.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement