TechoBoard.cpp 728 B

12345678910111213141516171819202122232425262728293031
  1. #include <Arduino.h>
  2. #include <Wire.h>
  3. #include "TechoBoard.h"
  4. #ifdef LILYGO_TECHO
  5. void TechoBoard::begin() {
  6. NRF52Board::begin();
  7. Wire.begin();
  8. pinMode(SX126X_POWER_EN, OUTPUT);
  9. digitalWrite(SX126X_POWER_EN, HIGH);
  10. delay(10); // give sx1262 some time to power up
  11. }
  12. uint16_t TechoBoard::getBattMilliVolts() {
  13. int adcvalue = 0;
  14. analogReference(AR_INTERNAL_3_0);
  15. analogReadResolution(12);
  16. delay(10);
  17. // ADC range is 0..3000mV and resolution is 12-bit (0..4095)
  18. adcvalue = analogRead(PIN_VBAT_READ);
  19. // Convert the raw value to compensated mv, taking the resistor-
  20. // divider into account (providing the actual LIPO voltage)
  21. return (uint16_t)((float)adcvalue * REAL_VBAT_MV_PER_LSB);
  22. }
  23. #endif