/********* Pleasedontcode.com **********
Pleasedontcode thanks you for automatic code generation! Enjoy your code!
- Terms and Conditions:
You have a non-exclusive, revocable, worldwide, royalty-free license
for personal and commercial use. Attribution is optional; modifications
are allowed, but you're responsible for code maintenance. We're not
liable for any loss or damage. For full terms,
please visit pleasedontcode.com/termsandconditions.
- Project: Button Sensor
- Source Code NOT compiled for: Arduino Uno
- Source Code created on: 2024-10-16 17:15:27
********* Pleasedontcode.com **********/
/****** SYSTEM REQUIREMENTS *****/
/****** SYSTEM REQUIREMENT 1 *****/
/* Implement a user-friendly interface using the */
/* EasyButton library to handle button presses on pin */
/* D2, triggering specific actions based on user */
/* input while ensuring responsiveness and */
/* reliability. */
/****** END SYSTEM REQUIREMENTS *****/
/****** DEFINITION OF LIBRARIES *****/
#include // https://github.com/evert-arias/EasyButton
#include // https://github.com/soylentOrange/Forced-BMX280
/****** FUNCTION PROTOTYPES *****/
void setup(void);
void loop(void);
/***** DEFINITION OF DIGITAL INPUT PINS *****/
const uint8_t aa_PushButton_PIN_D2 = 2;
/****** DEFINITION OF LIBRARIES CLASS INSTANCES *****/
// Instantiate EasyButton object for button handling
EasyButton button1(aa_PushButton_PIN_D2); // Initialize button1 on pin D2
// Instantiate the climate sensor using the default I2C bus and address
ForcedBMX280 climateSensor; // Correctly instantiate the climate sensor
void setup(void)
{
// Initialize serial communication for debugging
Serial.begin(115200);
// Setup button
button1.begin(); // Initialize the button
button1.onPressed([]() { // Define what happens when the button is pressed
Serial.println("Button pressed"); // Print message to serial when button is pressed
});
// Initialize the climate sensor
if (climateSensor.begin() != ERROR_OK) {
Serial.println("Failed to initialize the climate sensor!"); // Error message if initialization fails
} else {
Serial.println("Climate sensor initialized successfully."); // Success message if initialization succeeds
}
}
void loop(void)
{
// Read the button state
button1.read(); // Check the button state
// Example: Get temperature from the climate sensor
int32_t temperature = climateSensor.getTemperatureCelsius(true); // Get temperature in Celsius
Serial.print("Temperature: ");
Serial.print(temperature / 100); // Print temperature in Celsius
Serial.println(" °C");
delay(2000); // Wait for 2 seconds before the next loop
}
/* END CODE */