Advertisement
pleasedontcode

Button Control rev_190

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 Control
  13.     - Source Code compiled for: Arduino Nano ESP32
  14.     - Source Code created on: 2024-01-14 12:50:20
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* if button is pressed so activate outdid */
  21. /****** END SYSTEM REQUIREMENTS *****/
  22.  
  23. /****** DEFINITION OF LIBRARIES *****/
  24. #include <Arduino.h>
  25. #include <EasyButton.h>
  26.  
  27. /****** FUNCTION PROTOTYPES *****/
  28. void setup(void);
  29. void loop(void);
  30.  
  31. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  32. const uint8_t button_PushButton_PIN_D2 = 2;
  33.  
  34. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  35. const uint8_t outdig_PIN_D3 = 3;
  36.  
  37. /***** DEFINITION OF PWM OUTPUT PINS *****/
  38. const uint8_t outpwm_PIN_D12 = 12;
  39.  
  40. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  41. EasyButton button(button_PushButton_PIN_D2);
  42.  
  43. void setup(void)
  44. {
  45.   // put your setup code here, to run once:
  46.   pinMode(button_PushButton_PIN_D2, INPUT_PULLUP);
  47.   pinMode(outdig_PIN_D3, OUTPUT);
  48.   pinMode(outpwm_PIN_D12, OUTPUT);
  49. }
  50.  
  51. void loop(void)
  52. {
  53.   // put your main code here, to run repeatedly:
  54.   button.read(); // Read the button state
  55.  
  56.   if (button.isPressed()) {
  57.     digitalWrite(outdig_PIN_D3, HIGH); // Activate the digital output pin
  58.     analogWrite(outpwm_PIN_D12, 255); // Set PWM output to maximum value
  59.   } else {
  60.     digitalWrite(outdig_PIN_D3, LOW); // Deactivate the digital output pin
  61.     analogWrite(outpwm_PIN_D12, 0); // Set PWM output to minimum value
  62.   }
  63. }
  64.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement