Advertisement
pleasedontcode

"Bluetooth Button" rev_01

Jan 25th, 2025
75
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: "Bluetooth Button"
  13.     - Source Code NOT compiled for: Arduino Nano ESP32
  14.     - Source Code created on: 2025-01-25 09:51:14
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Que cuando pulse el Mypush que mediante Bluetooth */
  21.     /* haga de teclado y escriba 1234567 */
  22. /****** END SYSTEM REQUIREMENTS *****/
  23.  
  24. /* START CODE */
  25.  
  26. /****** DEFINITION OF LIBRARIES *****/
  27. #include <EasyButton.h> //https://github.com/evert-arias/EasyButton
  28. #include <BluetoothSerial.h> // Include Bluetooth Serial library
  29.  
  30. /****** FUNCTION PROTOTYPES *****/
  31. void setup(void);
  32. void loop(void);
  33.  
  34. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  35. const uint8_t Mypush_PushButton_PIN_D2 = 2;
  36.  
  37. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  38. EasyButton button(Mypush_PushButton_PIN_D2); // Create an instance of the EasyButton
  39. BluetoothSerial SerialBT; // Create an instance of the Bluetooth Serial
  40.  
  41. /****** CALLBACK FUNCTION *****/
  42. void onPressed() {
  43.     SerialBT.println("1234567"); // Send the string "1234567" via Bluetooth
  44. }
  45.  
  46. void setup(void) {
  47.     // put your setup code here, to run once:
  48.     Serial.begin(115200); // Initialize Serial for debugging
  49.     SerialBT.begin("ESP32_BT"); // Initialize Bluetooth with a name
  50.     pinMode(Mypush_PushButton_PIN_D2, INPUT_PULLUP);
  51.  
  52.     // Initialize the button
  53.     button.begin();
  54.     button.onPressed(onPressed); // Attach the onPressed callback
  55. }
  56.  
  57. void loop(void) {
  58.     // put your main code here, to run repeatedly:
  59.     button.read(); // Continuously read the status of the button
  60. }
  61.  
  62. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement