Advertisement
pleasedontcode

Button Control rev_01

Mar 27th, 2024
83
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: Button Control
  13.     - Source Code compiled for: Arduino Uno
  14.     - Source Code created on: 2024-03-27 15:26:08
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Menghidupkan LED, ketika tombol ditekan */
  21. /****** SYSTEM REQUIREMENT 2 *****/
  22.     /* Menghidupkan LED, ketika tombol ditekan */
  23. /****** END SYSTEM REQUIREMENTS *****/
  24.  
  25. /****** DEFINITION OF LIBRARIES *****/
  26. #include <EasyButton.h> //https://github.com/evert-arias/EasyButton
  27.  
  28. /****** FUNCTION PROTOTYPES *****/
  29. void setup(void);
  30. void loop(void);
  31.  
  32. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  33. const uint8_t Power_PushButton_PIN_D2 = 2;
  34. const uint8_t Power_PushButton_PIN_D3 = 3;
  35.  
  36. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  37. EasyButton Power_PushButton_D2(Power_PushButton_PIN_D2);
  38. EasyButton Power_PushButton_D3(Power_PushButton_PIN_D3);
  39.  
  40. /****** SYSTEM REQUIREMENTS *****/
  41. /****** SYSTEM REQUIREMENT 1 *****/
  42. const uint8_t LED_PIN_D4 = 4; // Define the pin for the LED
  43. bool isButtonD2Pressed = false; // Flag to keep track of button D2 state
  44.  
  45. /****** SYSTEM REQUIREMENT 2 *****/
  46. const uint8_t LED_PIN_D5 = 5; // Define the pin for the LED
  47. bool isButtonD3Pressed = false; // Flag to keep track of button D3 state
  48.  
  49. void setup(void)
  50. {
  51.   // put your setup code here, to run once:
  52.  
  53.   pinMode(Power_PushButton_PIN_D2, INPUT_PULLUP);
  54.   pinMode(Power_PushButton_PIN_D3, INPUT_PULLUP);
  55.  
  56.   Power_PushButton_D2.begin();
  57.   Power_PushButton_D3.begin();
  58.  
  59.   /****** SYSTEM REQUIREMENT 1 *****/
  60.   pinMode(LED_PIN_D4, OUTPUT); // Set the LED pin as output
  61.  
  62.   /****** SYSTEM REQUIREMENT 2 *****/
  63.   pinMode(LED_PIN_D5, OUTPUT); // Set the LED pin as output
  64. }
  65.  
  66. void loop(void)
  67. {
  68.   // put your main code here, to run repeatedly:
  69.  
  70.   Power_PushButton_D2.read();
  71.   Power_PushButton_D3.read();
  72.  
  73.   // Add your code to handle button events here
  74.  
  75.   /****** SYSTEM REQUIREMENT 1 *****/
  76.   if (Power_PushButton_D2.wasPressed()) {
  77.     isButtonD2Pressed = true;
  78.     digitalWrite(LED_PIN_D4, HIGH); // Turn on the LED
  79.   }
  80.   if (Power_PushButton_D2.wasReleased()) {
  81.     isButtonD2Pressed = false;
  82.     digitalWrite(LED_PIN_D4, LOW); // Turn off the LED
  83.   }
  84.  
  85.   /****** SYSTEM REQUIREMENT 2 *****/
  86.   if (Power_PushButton_D3.wasPressed()) {
  87.     isButtonD3Pressed = true;
  88.     digitalWrite(LED_PIN_D5, HIGH); // Turn on the LED
  89.   }
  90.   if (Power_PushButton_D3.wasReleased()) {
  91.     isButtonD3Pressed = false;
  92.     digitalWrite(LED_PIN_D5, LOW); // Turn off the LED
  93.   }
  94. }
  95.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement