Advertisement
pleasedontcode

Button Control rev_01

Dec 24th, 2023
96
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 Mega
  14.     - Source Code created on: 2023-12-24 07:20:59
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Reads 14pcs of digital inputs, and sends the */
  21.     /* status of the input as CAN-bus message.  10 */
  22.     /* digital outputs that can be configured easily with */
  23.     /* variables for on-off depending on configured */
  24.     /* digital input status. */
  25. /****** END SYSTEM REQUIREMENTS *****/
  26.  
  27. /****** DEFINITION OF LIBRARIES *****/
  28. #include <Arduino.h>
  29. #include <EasyButton.h>
  30.  
  31. /****** FUNCTION PROTOTYPES *****/
  32. void setup(void);
  33. void loop(void);
  34.  
  35. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  36. const uint8_t DI1_PushButton_PIN_D2 = 2;
  37.  
  38. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  39. const uint8_t DO1_Led_PIN_D3 = 3;
  40. const uint8_t DO2_Led_PIN_D4 = 4;
  41.  
  42. /****** DEFINITION OF LIBRARY CLASS INSTANCES *****/
  43. EasyButton button1(DI1_PushButton_PIN_D2, 35, true, true);
  44.  
  45. void onButton1Pressed()
  46. {
  47.     // Button1 Pressed callback function
  48. }
  49.  
  50. void setup(void)
  51. {
  52.     // put your setup code here, to run once:
  53.  
  54.     // Initialize the button1 object
  55.     // Enable pull-up resistor for the push button
  56.     button1.begin();
  57.  
  58.     // Attach the onButton1Pressed function as the callback for button1 pressed event
  59.     button1.onPressed(onButton1Pressed);
  60.  
  61.     // Set the defined digital output pins as output mode
  62.     pinMode(DO1_Led_PIN_D3, OUTPUT);
  63.     pinMode(DO2_Led_PIN_D4, OUTPUT);
  64. }
  65.  
  66. void loop(void)
  67. {
  68.     // put your main code here, to run repeatedly:
  69.  
  70.     // Read the state of the button1
  71.     button1.read();
  72.  
  73.     // Check the state of button1 and set the corresponding digital output pins accordingly
  74.     if (button1.isPressed())
  75.     {
  76.         // Set DO1_Led_PIN_D3 HIGH when button1 is pressed
  77.         digitalWrite(DO1_Led_PIN_D3, HIGH);
  78.     }
  79.     else
  80.     {
  81.         // Set DO1_Led_PIN_D3 LOW when button1 is released
  82.         digitalWrite(DO1_Led_PIN_D3, LOW);
  83.     }
  84.  
  85.     // ... (Configure the other digital output pins based on other digital input status)
  86. }
  87.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement