/********* 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: BMX280 Readings - Source Code NOT compiled for: Arduino Uno - Source Code created on: 2025-10-12 12:59:23 ********* Pleasedontcode.com **********/ /****** SYSTEM REQUIREMENTS *****/ /****** SYSTEM REQUIREMENT 1 *****/ /* 1) Use D2 with INPUT_PULLUP and EasyButton to emit */ /* a debounced pressed event to Serial. 2) On press, */ /* read BMX280 via forcedBMX280 and print */ /* pressure/temp. 3) Rely only on */ /* button1_PushButton_PIN_D2; no extra pins/libs */ /* beyond those listed. */ /****** END SYSTEM REQUIREMENTS *****/ /* START CODE */ /****** DEFINITION OF LIBRARIES *****/ #include #include // https://github.com/soylentOrange/Forced-BMX280 #include /****** FUNCTION PROTOTYPES *****/ void setup(void); void loop(void); void onButtonPressed(void); /***** DEFINITION OF DIGITAL INPUT PINS *****/ const uint8_t button1_PushButton_PIN_D2 = 2; // D2 /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/ ForcedBMX280 climateSensor = ForcedBMX280(); EasyButton button1 = EasyButton(button1_PushButton_PIN_D2); void setup(void) { // Initialize serial port for debugging and output Serial.begin(115200); while (!Serial) { ; // wait for serial port to connect. Needed for native USB devices } // Initialize I2C bus Wire.begin(); // Initialize BMX280 sensor in forced mode (no continuous sampling) climateSensor.begin(); // Initialize button with debounced callback on D2 (INPUT_PULLUP by EasyButton) button1.begin(); button1.onPressed(onButtonPressed); } void loop(void) { // Update button state to generate debounced events button1.update(); } // Debounced button press handler void onButtonPressed(void) { Serial.println("Button pressed"); // Take a forced measurement to update data climateSensor.takeForcedMeasurement(); // Read temperature in hundredths of degrees Celsius int32_t temperatureC100 = climateSensor.getTemperatureCelsius(true); Serial.print("Temperature: "); Serial.print(temperatureC100/100); Serial.print("."); int32_t frac = temperatureC100 % 100; if (frac < 0) frac = -frac; if (frac < 10) Serial.print("0"); Serial.println(frac); Serial.println(" C"); // Read pressure (hPa with two decimals). If not available on the used class, this call // will either be ignored by the library or may return a valid value depending on the build. uint32_t pressurePa100 = climateSensor.getPressure(true); Serial.print("Pressure: "); Serial.print(pressurePa100/100); Serial.print("."); uint32_t pDec = pressurePa100 % 100; if (pDec < 10) Serial.print("0"); Serial.println(pDec); Serial.println(" hPa"); Serial.println(""); } /* END CODE */