Fixed issue with analog.

This commit is contained in:
Yohan Boujon 2024-12-03 16:55:17 +01:00
parent bbb968e1a5
commit 88e635bfb7
2 changed files with 7 additions and 2 deletions

View file

@ -13,13 +13,13 @@ void Sensor::init(const uint8_t pin)
float Sensor::get_analog() float Sensor::get_analog()
{ {
return analogRead(_pin); return (static_cast<float>(analogRead(_pin))/(1<<12))*3.3f;
} }
// Normally should be 5V, but the ADC can only see up to 3.3 on 12 bits // Normally should be 5V, but the ADC can only see up to 3.3 on 12 bits
float Sensor::get_RSR0() float Sensor::get_RSR0()
{ {
float sensor_volt=(float)(analogRead(_pin))/((1<<12)*3.3); float sensor_volt=(static_cast<float>(analogRead(_pin))/(1<<12))*3.3f;
float RS_gas = (3.3-sensor_volt)/sensor_volt; float RS_gas = (3.3-sensor_volt)/sensor_volt;
return RS_gas/R0; return RS_gas/R0;
} }

View file

@ -113,7 +113,12 @@ void setup() {
// Initialize SSD1306 // Initialize SSD1306
Init_SSD1306(); Init_SSD1306();
delay(5000); delay(5000);
// Initialize Gateway from LoRa
initGateway(); initGateway();
// Initialize Sensor
gaz_sensor.init(SENSOR_PIN);
} }
void loop() { void loop() {