Advertisement
pleasedontcode

Button Sensor rev_01

Oct 16th, 2024
55
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 Sensor
  13.     - Source Code NOT compiled for: Arduino Uno
  14.     - Source Code created on: 2024-10-16 17:15:27
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Implement a user-friendly interface using the */
  21.     /* EasyButton library to handle button presses on pin */
  22.     /* D2, triggering specific actions based on user */
  23.     /* input while ensuring responsiveness and */
  24.     /* reliability. */
  25. /****** END SYSTEM REQUIREMENTS *****/
  26.  
  27. /****** DEFINITION OF LIBRARIES *****/
  28. #include <EasyButton.h>   // https://github.com/evert-arias/EasyButton
  29. #include <forcedBMX280.h> // https://github.com/soylentOrange/Forced-BMX280
  30.  
  31. /****** FUNCTION PROTOTYPES *****/
  32. void setup(void);
  33. void loop(void);
  34.  
  35. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  36. const uint8_t aa_PushButton_PIN_D2 = 2;
  37.  
  38. /****** DEFINITION OF LIBRARIES CLASS INSTANCES *****/
  39. // Instantiate EasyButton object for button handling
  40. EasyButton button1(aa_PushButton_PIN_D2); // Initialize button1 on pin D2
  41. // Instantiate the climate sensor using the default I2C bus and address
  42. ForcedBMX280 climateSensor; // Correctly instantiate the climate sensor
  43.  
  44. void setup(void)
  45. {
  46.     // Initialize serial communication for debugging
  47.     Serial.begin(115200);
  48.    
  49.     // Setup button
  50.     button1.begin(); // Initialize the button
  51.     button1.onPressed([]() { // Define what happens when the button is pressed
  52.         Serial.println("Button pressed"); // Print message to serial when button is pressed
  53.     });
  54.  
  55.     // Initialize the climate sensor
  56.     if (climateSensor.begin() != ERROR_OK) {
  57.         Serial.println("Failed to initialize the climate sensor!"); // Error message if initialization fails
  58.     } else {
  59.         Serial.println("Climate sensor initialized successfully."); // Success message if initialization succeeds
  60.     }
  61. }
  62.  
  63. void loop(void)
  64. {
  65.     // Read the button state
  66.     button1.read(); // Check the button state
  67.  
  68.     // Example: Get temperature from the climate sensor
  69.     int32_t temperature = climateSensor.getTemperatureCelsius(true); // Get temperature in Celsius
  70.     Serial.print("Temperature: ");
  71.     Serial.print(temperature / 100); // Print temperature in Celsius
  72.     Serial.println(" °C");
  73.  
  74.     delay(2000); // Wait for 2 seconds before the next loop
  75. }
  76.  
  77. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement