Browse Source

implemented a calibration process for the atomizer library

master
Luis Rodil-Fernandez 3 years ago
parent
commit
c90295a57f
  1. 53
      src/atomizer.h

53
src/atomizer.h

@ -1,28 +1,67 @@
#include <Arduino.h>
#include <corestats.h>
#include <nanolog.h>
/**
* Simple controller library for an ultrasonic atomizer
* used in atomizers, scent dispensers, etc.
* Simple controller library for a cheap
* ultrasonic atomizer used in humidifiers,
* scent dispensers, etc.
*
* studio derfunke (c) 2022
*/
class Atomizer {
int pinSwitch;
int pinSensor;
u_int lastToggle; // since last toggle action
u_int lastToggle; // timestamp of last toggle action
MinMaxScaler minmax;
public:
Atomizer(int pin) : pinSwitch(pin) {
Atomizer(int pin1, int pin2)
: pinSwitch(pin1),
pinSensor(pin2) {
pinMode(PIN_ATOMIZER, OUTPUT);
pinMode(PIN_ATOMIZER_LDR, INPUT);
}
bool debug() {
void debug() {
int ldr = analogRead(pinSensor);
Serial.print(ldr);
LOG(ldr); LOG_NEW_LINE
}
void calibrate() {
int reading;
float s;
int i, j;
LOG("Calibrating atomizer actuation..."); LOG_NEW_LINE
for(i = 0; i < 5; i++) {
LOG("Calibration loop "); LOG(i); LOG_NEW_LINE
// do some readings on current state
for(int i = 0; i < 10; i++) {
reading = analogRead(pinSensor);
minmax.put( reading );
}
toggle(); // change state
// do some more readings
for(int i = 0; i < 10; i++) {
reading = analogRead(pinSensor);
minmax.put( reading );
}
toggle(); // change state again
} // how many calibration steps
}
bool is_on() {
int ldr = analogRead(pinSensor);
return ldr > 300;
float s = minmax.put( ldr ); // run our value through a minmax scaler
return (s > 0.85);
}
u_int elapsed() {

Loading…
Cancel
Save