Advertisement
pleasedontcode

"Digital Input/Output" rev_03

Apr 7th, 2024
71
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 Input/Output"
  13.     - Source Code compiled for: Arduino Uno
  14.     - Source Code created on: 2024-04-07 10:06:03
  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.  
  30. /****** FUNCTION PROTOTYPES *****/
  31. void setup(void);
  32. void loop(void);
  33. void updateOutputs(void);
  34.  
  35. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  36. const uint8_t tilt_PushButton_PIN_D2 = 2;
  37.  
  38. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  39. const uint8_t red_LED_PIN_D3 = 3;
  40. const uint8_t green_LED_PIN_D4 = 4;
  41. const uint8_t bazer_PassiveBuzzer_Signal_PIN_D5 = 5;
  42.  
  43. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  44. /***** used to store raw data *****/
  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. /***** used to store data after characteristic curve transformation *****/
  51. float red_LED_PIN_D3_phyData = 0.0;
  52. float green_LED_PIN_D4_phyData = 0.0;
  53. float bazer_PassiveBuzzer_Signal_PIN_D5_phyData = 0.0;
  54.  
  55. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  56. EasyButton tilt_PushButton(tilt_PushButton_PIN_D2);
  57.  
  58. bool isButtonPressed = false;
  59. int blinkCount = 0;
  60.  
  61. void setup(void)
  62. {
  63.   // put your setup code here, to run once:
  64.   pinMode(tilt_PushButton_PIN_D2, INPUT_PULLUP);
  65.  
  66.   pinMode(red_LED_PIN_D3, OUTPUT);
  67.   pinMode(green_LED_PIN_D4, OUTPUT);
  68.   pinMode(bazer_PassiveBuzzer_Signal_PIN_D5, OUTPUT);
  69.  
  70.   tilt_PushButton.begin();
  71.   tilt_PushButton.onPressed([]() {
  72.     // Button pressed event handler
  73.     Serial.println("Button pressed");
  74.     isButtonPressed = true;
  75.   });
  76. }
  77.  
  78. void loop(void)
  79. {
  80.   // put your main code here, to run repeatedly:
  81.   updateOutputs(); // Refresh output data
  82.  
  83.   tilt_PushButton.read(); // Read button state
  84.  
  85.   if (isButtonPressed) {
  86.     // Flashes the green LED 10 times
  87.     if (blinkCount < 10) {
  88.       digitalWrite(green_LED_PIN_D4, HIGH);
  89.       delay(500);
  90.       digitalWrite(green_LED_PIN_D4, LOW);
  91.       delay(500);
  92.       blinkCount++;
  93.     } else {
  94.       // Turn on the red LED for 15 seconds
  95.       digitalWrite(green_LED_PIN_D4, LOW);
  96.       digitalWrite(red_LED_PIN_D3, HIGH);
  97.       delay(15000);
  98.       digitalWrite(red_LED_PIN_D3, LOW);
  99.       isButtonPressed = false;
  100.       blinkCount = 0;
  101.     }
  102.   }
  103. }
  104.  
  105. void updateOutputs()
  106. {
  107.   digitalWrite(red_LED_PIN_D3, red_LED_PIN_D3_rawData);
  108.   digitalWrite(green_LED_PIN_D4, green_LED_PIN_D4_rawData);
  109.   digitalWrite(bazer_PassiveBuzzer_Signal_PIN_D5, bazer_PassiveBuzzer_Signal_PIN_D5_rawData);
  110. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement