MistyGro API
C++ API for MistyGro's ESP32 controller based on the Arduino framework
adc.h
Go to the documentation of this file.
1 /*
2  * Copyright 2023 Myron Rodrigues
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef _ADC_H_
18 #define _ADC_H_
19 
20 #include <Adafruit_ADS1X15.h>
21 #include <Arduino.h>
22 #include <SPI.h>
23 #include <Wire.h>
24 
25 enum class ADCChannel { ph = 0, ec = 1, ldr = 3 };
26 
27 class ADC
28 {
29 private:
30  Adafruit_ADS1115 ads_;
31  TwoWire i2c_bus_;
32 
33 public:
34  explicit ADC();
35 
43  void begin(int addr, int sda_pin, int scl_pin);
44 
51  int16_t read(ADCChannel ch);
52 
59  float read_voltage(ADCChannel ch);
60 };
61 
62 #endif
ADCChannel
Definition: adc.h:25
Definition: adc.h:28
void begin(int addr, int sda_pin, int scl_pin)
Definition: adc.cpp:21
ADC()
Definition: adc.cpp:19
float read_voltage(ADCChannel ch)
Read voltage from ADC channel (computes voltage using the set fixed gain)
Definition: adc.cpp:39
int16_t read(ADCChannel ch)
Read ADC value from channel.
Definition: adc.cpp:34