Advertisement
pleasedontcode

Button Monitor rev_16

Dec 18th, 2023
102
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 Monitor
  13.     - Source Code compiled for: Arduino Nano
  14.     - Source Code created on: 2023-12-19 01:16:07
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Convert an int variable 1234 in string and print */
  21.     /* on serial monitor */
  22. /****** END SYSTEM REQUIREMENTS *****/
  23.  
  24. /****** DEFINITION OF LIBRARIES *****/
  25. #include <Arduino.h>
  26. #include <EasyButton.h>
  27.  
  28. /****** FUNCTION PROTOTYPES *****/
  29. void setup(void);
  30. void loop(void);
  31.  
  32. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  33. const uint8_t Button_PushButton_PIN_D2 = 2;
  34.  
  35. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  36. EasyButton button(Button_PushButton_PIN_D2); // Create an instance of EasyButton
  37.  
  38. void setup(void)
  39. {
  40.   // put your setup code here, to run once:
  41.   Serial.begin(9600); // Initialize serial communication
  42.  
  43.   pinMode(Button_PushButton_PIN_D2, INPUT_PULLUP);
  44.  
  45.   button.begin(); // Initialize the button
  46.   button.onPressed([]() {
  47.     // This function will be called when the button is pressed
  48.     Serial.println("Button has been pressed");
  49.   });
  50. }
  51.  
  52. void loop(void)
  53. {
  54.   // put your main code here, to run repeatedly:
  55.   button.read(); // Read the button state
  56.  
  57.   // System Requirement 1: Convert an int variable 1234 to a string and print it on the serial monitor
  58.   int num = 1234;
  59.   char str[10];
  60.   sprintf(str, "%d", num);
  61.   Serial.println(str);
  62. }
  63.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement