MistyGro API
C++ API for MistyGro's ESP32 controller based on the Arduino framework
test_ldr.cpp
Go to the documentation of this file.
1 // Copyright 2023 Myron Rodrigues
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include "ldr.h"
16 #include "utility.h"
17 
19 LDR ldr(10, &adc);
20 
21 void setup()
22 {
23  Serial.begin(115200);
24  adc.begin(constants::adc_bus_addr, pin::adc_sda, pin::adc_scl);
25  Serial.println("LDR test/calib");
26 }
27 
28 void loop()
29 {
30  if (Serial.available() > 0) {
31  Serial.print("Reading LDR voltage: ");
32  Serial.println(ldr.read_voltage());
33  delay(1000);
34  }
35 }
Definition: adc.h:28
void begin(int addr, int sda_pin, int scl_pin)
Definition: adc.cpp:21
Light dependent resistor wrapper.
Definition: ldr.h:29
float read_voltage()
Read voltage from ADC for LDR. Make sure ADC is initialised before calling this method.
Definition: ldr.cpp:21
LDR ldr(10, &adc)
void setup()
Definition: test_ldr.cpp:21
ADC adc
Definition: test_ldr.cpp:18
void loop()
Definition: test_ldr.cpp:28