diff --git a/Config.h b/Config.h index d680bbc..b7ffce4 100644 --- a/Config.h +++ b/Config.h @@ -30,6 +30,7 @@ #define CO2_PURGE_RETRACTION_PERIOD 500 #define FILL_SENSORS_TIMER_FREQUENCY 100000 // 100ms This value needs to be defined in microseconds. #define FILL_SENSORS_TRIGGER 400 // Int between 0 and 1023 used to trigger the fill sensor: operating voltage(5v or 3.3v) / 1024 +#define VARIABLE_FILL_SENSOR_TRIGGER false // Use a potentiometer to adjust trigger value /** * Feature flags diff --git a/InputConfig.h b/InputConfig.h index 7631c4f..54dea40 100644 --- a/InputConfig.h +++ b/InputConfig.h @@ -30,6 +30,7 @@ #define BEER_FILL_SENSOR_1 A0 #define BEER_FILL_SENSOR_2 A1 #define BEER_FILL_SENSOR_3 A2 +#define BEER_FILL_SENSOR_POT A3 #define CO2_PURGE_SOL 4 #define FILL_RAIL_SOL 3 #define BEER_BELT_SOL 2 diff --git a/OpenBeerFiller.ino b/OpenBeerFiller.ino index 6633fe2..18929b9 100644 --- a/OpenBeerFiller.ino +++ b/OpenBeerFiller.ino @@ -41,6 +41,7 @@ volatile bool fillSensor3Triggered = false; bool idleMessageDisplayed = false; enum ProgramState {UNDEF,IDLE,START,FILLING,STOP}; ProgramState currentState = UNDEF; +int sensorValue; /** * *************************************************************************** @@ -66,6 +67,7 @@ void setupPins() { pinMode(BEER_FILL_SENSOR_1, INPUT); pinMode(BEER_FILL_SENSOR_2, INPUT); pinMode(BEER_FILL_SENSOR_3, INPUT); + pinMode(BEER_FILL_SENSOR_POT, INPUT); // Start/Stop button. pinMode(START_BUTTON, INPUT); @@ -83,13 +85,18 @@ void setupFillSensorsTimer() { * Check if the fill sensors have been triggered. */ void checkFillSensors() { - if (FILL_SENSORS_TRIGGER < analogRead(BEER_FILL_SENSOR_1)) { + if (VARIABLE_FILL_SENSOR_TRIGGER) { + sensorValue = analogRead(BEER_FILL_SENSOR_POT); + } else { + sensorValue = FILL_SENSORS_TRIGGER; + } + if (sensorValue < analogRead(BEER_FILL_SENSOR_1)) { triggerFullFillSensor1(); } - if (FILL_SENSORS_TRIGGER < analogRead(BEER_FILL_SENSOR_2)) { + if (sensorValue < analogRead(BEER_FILL_SENSOR_2)) { triggerFullFillSensor2(); } - if (FILL_SENSORS_TRIGGER < analogRead(BEER_FILL_SENSOR_3)) { + if (sensorValue < analogRead(BEER_FILL_SENSOR_3)) { triggerFullFillSensor3(); } }