Advertisement
pleasedontcode

Button Setup rev_193

Jan 14th, 2024
67
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 Setup
  13.     - Source Code compiled for: ESP32 DevKit V1
  14.     - Source Code created on: 2024-01-14 16:17:12
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* if button is pressed so set out to 128. */
  21. /****** END SYSTEM REQUIREMENTS *****/
  22.  
  23. /****** DEFINITION OF LIBRARIES *****/
  24. #include <Arduino.h>
  25. #include <EasyButton.h>
  26.  
  27. /****** SYSTEM REQUIREMENTS *****/
  28. // SYSTEM REQUIREMENT 1: If button is pressed, set output to 128
  29.  
  30. /****** FUNCTION PROTOTYPES *****/
  31. void setup(void);
  32. void loop(void);
  33.  
  34. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  35. const uint8_t butt_PushButton_PIN_D4 = 4;
  36. const uint8_t dit_PIN_D13 = 13;
  37. const uint8_t ditpullup_PIN_D14 = 14;
  38. const uint8_t ditpulldown_PIN_D16 = 16;
  39.  
  40. /****** DEFINITION OF LIBRARY CLASS INSTANCES *****/
  41. EasyButton pushButton(butt_PushButton_PIN_D4, 50);
  42.  
  43. void setup(void)
  44. {
  45.   // put your setup code here, to run once:
  46.   pinMode(dit_PIN_D13, OUTPUT);
  47.   digitalWrite(dit_PIN_D13, LOW);
  48.  
  49.   pinMode(ditpullup_PIN_D14, INPUT_PULLUP);
  50.   pinMode(ditpulldown_PIN_D16, INPUT_PULLDOWN);
  51.  
  52.   pushButton.begin();
  53. }
  54.  
  55. void loop(void)
  56. {
  57.   // put your main code here, to run repeatedly:
  58.  
  59.   pushButton.read();
  60.  
  61.   // Check if the pushButton is pressed
  62.   if (pushButton.isPressed())
  63.   {
  64.     analogWrite(dit_PIN_D13, 128); // Set the output to 128
  65.   }
  66.   else
  67.   {
  68.     analogWrite(dit_PIN_D13, 0); // Set the output to 0
  69.   }
  70. }
  71.  
  72.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement