Advertisement
pleasedontcode

LED Control rev_05

Apr 7th, 2024
81
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: LED Control
  13.     - Source Code compiled for: Arduino Uno
  14.     - Source Code created on: 2024-04-07 10:27:07
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Με το πάτημα του EasyButton που είναι συνδεδεμένο */
  21.     /* στον ακροδέκτη D2, το πράσινο LED που είναι */
  22.     /* συνδεδεμένο στον ακροδέκτη D4 θα αναβοσβήνει με */
  23.     /* ακρίβεια 10 φορές και στη συνέχεια θα σταματήσει */
  24.     /* να αναβοσβήνει. */
  25. /****** SYSTEM REQUIREMENT 2 *****/
  26.     /* Όταν η πράσινη λυχνία LED, που είναι συνδεδεμένη */
  27.     /* στον ακροδέκτη D4, σταματήσει να αναβοσβήνει, η */
  28.     /* κόκκινη λυχνία LED, που είναι συνδεδεμένη στην */
  29.     /* ακίδα D3, θα πρέπει να ανάβει για 15 δευτερόλεπτα */
  30.     /* και μετα να σβηνη */
  31. /****** END SYSTEM REQUIREMENTS *****/
  32.  
  33. /****** DEFINITION OF LIBRARIES *****/
  34. #include <EasyButton.h> //https://github.com/evert-arias/EasyButton
  35.  
  36. /****** FUNCTION PROTOTYPES *****/
  37. void setup(void);
  38. void loop(void);
  39. void onPressedForDuration();
  40.  
  41. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  42. const uint8_t tilt_PushButton_PIN_D2 = 2;
  43.  
  44. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  45. const uint8_t red_LED_PIN_D3 = 3;
  46. const uint8_t green_LED_PIN_D4 = 4;
  47.  
  48. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  49. /***** used to store raw data *****/
  50. bool red_LED_PIN_D3_rawData = 0;
  51. bool green_LED_PIN_D4_rawData = 0;
  52.  
  53. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  54. /***** used to store data after characteristic curve transformation *****/
  55. float red_LED_PIN_D3_phyData = 0.0;
  56. float green_LED_PIN_D4_phyData = 0.0;
  57.  
  58. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  59. EasyButton button(tilt_PushButton_PIN_D2);
  60.  
  61. void setup(void)
  62. {
  63.   // put your setup code here, to run once:
  64.  
  65.   pinMode(tilt_PushButton_PIN_D2, INPUT_PULLUP);
  66.  
  67.   pinMode(red_LED_PIN_D3, OUTPUT);
  68.   pinMode(green_LED_PIN_D4, OUTPUT);
  69. }
  70.  
  71. void loop(void)
  72. {
  73.   // put your main code here, to run repeatedly:
  74.   button.read();   // Continuously read the status of the button
  75.   updateOutputs(); // Refresh output data
  76. }
  77.  
  78. void updateOutputs()
  79. {
  80.   if (button.isPressed()) { // Check if button is pressed
  81.     // Toggle green LED 10 times
  82.     for (int i = 0; i < 10; i++) {
  83.       green_LED_PIN_D4_rawData = !green_LED_PIN_D4_rawData;
  84.       digitalWrite(green_LED_PIN_D4, green_LED_PIN_D4_rawData);
  85.       delay(100);
  86.     }
  87.   } else {
  88.     green_LED_PIN_D4_rawData = 0;
  89.     digitalWrite(green_LED_PIN_D4, green_LED_PIN_D4_rawData);
  90.   }
  91.  
  92.   // Check if green LED has stopped blinking
  93.   if (!green_LED_PIN_D4_rawData) {
  94.     // Turn on red LED for 15 seconds
  95.     red_LED_PIN_D3_rawData = 1;
  96.     digitalWrite(red_LED_PIN_D3, red_LED_PIN_D3_rawData);
  97.     delay(15000); // 15 seconds
  98.     red_LED_PIN_D3_rawData = 0;
  99.     digitalWrite(red_LED_PIN_D3, red_LED_PIN_D3_rawData);
  100.   }
  101. }
  102.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement