Advertisement
pleasedontcode

"Tilt Control" rev_02

Apr 6th, 2024
59
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: "Tilt Control"
  13.     - Source Code compiled for: Arduino Uno
  14.     - Source Code created on: 2024-04-06 11:17:28
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* when the easy button was pressed, the green led */
  21.     /* 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>    //https://github.com/evert-arias/EasyButton
  29. #include <ezBuzzer.h>    //https://github.com/ArduinoGetStarted/buzzer
  30.  
  31. /****** FUNCTION PROTOTYPES *****/
  32. void setup(void);
  33. void loop(void);
  34. void flashGreenLED(void);
  35. void turnOnRedLED(void);
  36.  
  37. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  38. const uint8_t tilt_PushButton_PIN_D2 = 2;
  39.  
  40. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  41. const uint8_t red_LED_PIN_D3 = 3;
  42. const uint8_t green_LED_PIN_D4 = 4;
  43. const uint8_t bazer_PassiveBuzzer_Signal_PIN_D5 = 5;
  44.  
  45. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  46. /***** used to store raw data *****/
  47. bool red_LED_PIN_D3_rawData = 0;
  48. bool green_LED_PIN_D4_rawData = 0;
  49. bool bazer_PassiveBuzzer_Signal_PIN_D5_rawData = 0;
  50.  
  51. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  52. /***** used to store data after characteristic curve transformation *****/
  53. float red_LED_PIN_D3_phyData = 0.0;
  54. float green_LED_PIN_D4_phyData = 0.0;
  55. float bazer_PassiveBuzzer_Signal_PIN_D5_phyData = 0.0;
  56.  
  57. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  58. EasyButton tiltPushButton(tilt_PushButton_PIN_D2, true); // Initialize EasyButton object for tilt push button
  59. ezBuzzer buzzer(bazer_PassiveBuzzer_Signal_PIN_D5); // Initialize ezBuzzer object for passive buzzer
  60.  
  61. bool greenLedFlashCompleted = false;
  62.  
  63. void setup(void)
  64. {
  65.     // put your setup code here, to run once:
  66.  
  67.     pinMode(tilt_PushButton_PIN_D2, INPUT_PULLUP);
  68.  
  69.     pinMode(red_LED_PIN_D3, OUTPUT);
  70.     pinMode(green_LED_PIN_D4, OUTPUT);
  71.     pinMode(bazer_PassiveBuzzer_Signal_PIN_D5, OUTPUT);
  72.  
  73.     tiltPushButton.begin(); // Start monitoring the tilt push button
  74. }
  75.  
  76. void loop(void)
  77. {
  78.     // put your main code here, to run repeatedly:
  79.  
  80.     updateOutputs(); // Refresh output data
  81.  
  82.     tiltPushButton.read(); // Read the tilt push button state
  83.  
  84.     // Check if the tilt push button is pressed
  85.     if (tiltPushButton.isPressed())
  86.     {
  87.         flashGreenLED();
  88.     }
  89.  
  90.     // Check if the green LED has completed flashing
  91.     if (greenLedFlashCompleted)
  92.     {
  93.         turnOnRedLED();
  94.     }
  95. }
  96.  
  97. void flashGreenLED()
  98. {
  99.     // Flash the green LED 10 times
  100.     for (int i = 0; i < 10; i++)
  101.     {
  102.         green_LED_PIN_D4_rawData = HIGH;
  103.         delay(500);
  104.         green_LED_PIN_D4_rawData = LOW;
  105.         delay(500);
  106.     }
  107.  
  108.     greenLedFlashCompleted = true;
  109. }
  110.  
  111. void turnOnRedLED()
  112. {
  113.     // Turn on the red LED for 15 seconds
  114.     red_LED_PIN_D3_rawData = HIGH;
  115.     delay(15000);
  116.     red_LED_PIN_D3_rawData = LOW;
  117.  
  118.     // Reset the green LED flag
  119.     greenLedFlashCompleted = false;
  120. }
  121.  
  122. void updateOutputs()
  123. {
  124.     digitalWrite(red_LED_PIN_D3, red_LED_PIN_D3_rawData);
  125.     digitalWrite(green_LED_PIN_D4, green_LED_PIN_D4_rawData);
  126.     digitalWrite(bazer_PassiveBuzzer_Signal_PIN_D5, bazer_PassiveBuzzer_Signal_PIN_D5_rawData);
  127. }
  128.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement