Skip to content

Commit

Permalink
Fixed FeatherS3 ADC 3.0.0 errors
Browse files Browse the repository at this point in the history
  • Loading branch information
UnexpectedMaker committed May 30, 2024
1 parent c4bb887 commit ad89146
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=UMS3 Helper
version=1.1.0
version=1.1.1
author=UnexpectedMaker
maintainer=UnexpectedMaker
sentence=Helper library for UnexpectedMaker S3 boards
Expand Down
12 changes: 10 additions & 2 deletions src/UMS3.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Updated for ESP32 Arduino Core 3.0.0 support
// May 30, 2024 - Seon Rozenblum (Unexpected Maker)
// May 31, 2024 - Seon Rozenblum (Unexpected Maker)

#ifndef _UMS3_H
#define _UMS3_H
Expand All @@ -16,6 +16,7 @@
#define ALS_ADC_CHANNEL ADC1_GPIO4_CHANNEL
#define VBAT_ADC_PIN 2
#define ALS_ADC_PIN 4
#else
#error \
"The board you have selected is not compatible with the UMS3 helper library"
#endif
Expand Down Expand Up @@ -169,9 +170,16 @@ class UMS3 {

#if defined(ARDUINO_FEATHERS3)
float getLightSensorVoltage() {
#if ESP_ARDUINO_VERSION_MAJOR < 3
uint32_t raw = adc1_get_raw(ALS_ADC_CHANNEL);
uint32_t millivolts = esp_adc_cal_raw_to_voltage(raw, &adc_cal);
return millivolts / 1000.0f;
#else
uint32_t millivolts = analogReadMilliVolts(VBAT_ADC_PIN);
#endif
const uint32_t upper_divider = 442;
const uint32_t lower_divider = 160;
return (float)(upper_divider + lower_divider) / lower_divider / 1000 *
millivolts;
}
#endif

Expand Down

0 comments on commit ad89146

Please sign in to comment.