firmware wip - sum analog sensor data and get middle value

This commit is contained in:
Marcus 2024-05-11 04:07:40 +02:00
parent cbee2c89be
commit b03968b577
3 changed files with 17 additions and 62 deletions

1
.gitignore vendored
View file

@ -2,3 +2,4 @@ KiCad/CanGrow/CanGrow-backups
KiCad/CanGrow/CanGrow.kicad_sch-bak KiCad/CanGrow/CanGrow.kicad_sch-bak
KiCad/CanGrow/fp-info-cache KiCad/CanGrow/fp-info-cache
KiCad/CanGrow/gerber/*.zip KiCad/CanGrow/gerber/*.zip
Arduino/CanGrow/CanGrow.geany

View file

@ -1,57 +0,0 @@
[editor]
line_wrapping=false
line_break_column=72
auto_continue_multiline=true
[file_prefs]
final_new_line=true
ensure_convert_new_lines=false
strip_trailing_spaces=false
replace_tabs=false
[indentation]
indent_width=2
indent_type=0
indent_hard_tab_width=8
detect_indent=false
detect_indent_width=false
indent_mode=2
[project]
name=CanGrow
base_path=./
description=
file_patterns=.ino,;.h;
[long line marker]
long_line_behaviour=1
long_line_column=72
[files]
current_page=1
FILE_NAME_0=0;Arduino;0;EUTF-8;0;1;0;.%2FCanGrow.ino;0;2
FILE_NAME_1=0;C++;0;EUTF-8;0;1;0;.%2FCanGrow_HTML.h;0;2
FILE_NAME_2=0;C++;0;EUTF-8;0;1;0;.%2FCanGrow_Init.h;0;2
FILE_NAME_3=0;C++;0;EUTF-8;0;1;0;.%2FCanGrow_Logo.h;0;2
FILE_NAME_4=0;C++;0;EUTF-8;0;1;0;.%2FCanGrow_PinAssignments.h;0;2
FILE_NAME_5=0;C++;0;EUTF-8;0;1;0;.%2FCanGrow_Sensors.h;0;2
FILE_NAME_6=0;C++;0;EUTF-8;0;1;0;.%2FCanGrow_SysFunctions.h;0;2
FILE_NAME_7=0;C++;0;EUTF-8;0;1;0;.%2FCanGrow_WebFunctions.h;0;2
[build-menu]
C++FT_00_LB=_Compile
C++FT_00_CM=~/.local/bin/arduino-cli --no-color compile -b esp8266:esp8266:d1_mini_clone "%d/CanGrow.ino"
C++FT_00_WD=
filetypes=C++;Arduino;
ArduinoFT_00_LB=_Build
ArduinoFT_00_CM=~/.local/bin/arduino-cli --no-color compile -b esp8266:esp8266:d1_mini_clone "%d/CanGrow.ino"
ArduinoFT_00_WD=
ArduinoFT_01_LB=Build & Upload
ArduinoFT_01_CM=~/.local/bin/arduino-cli --no-color compile -v -b esp8266:esp8266:d1_mini_clone -u -p /dev/ttyUSB0 "%d/CanGrow.ino"
ArduinoFT_01_WD=
C++FT_01_LB=_Build & Upload
C++FT_01_CM=~/.local/bin/arduino-cli --no-color compile -v -b esp8266:esp8266:d1_mini_clone -u -p /dev/ttyUSB0 "%d/CanGrow.ino"
C++FT_01_WD=
[VTE]
last_dir=~

View file

@ -57,9 +57,14 @@ int getWaterlevel() {
digitalWrite(PINwaterlevel, HIGH); digitalWrite(PINwaterlevel, HIGH);
// wait a bit to let the circuit stabilize // wait a bit to let the circuit stabilize
// TODO: replace delay() with millis() // TODO: replace delay() with millis()
delay(100); delay(50);
// get the value // get the value
waterlevelRAW = analogRead(PINanalog);
for(byte i = 0; i < 10 ; i++) {
waterlevelRAW = waterlevelRAW + analogRead(PINanalog);
}
waterlevelRAW = waterlevelRAW / 10;
// disable Vcc for the sensor to prevent electrolysis effect and release analog pin // disable Vcc for the sensor to prevent electrolysis effect and release analog pin
digitalWrite(PINwaterlevel, LOW); digitalWrite(PINwaterlevel, LOW);
@ -115,7 +120,7 @@ int getSoilmoisture(byte moistureSensor) {
*/ */
// value to return // value to return
int soilmoisture; int soilmoisture = 0;
// value for wet // value for wet
int wet; int wet;
// value for dry // value for dry
@ -129,9 +134,15 @@ int getSoilmoisture(byte moistureSensor) {
digitalWrite(PINsoilmoisture, HIGH); digitalWrite(PINsoilmoisture, HIGH);
// wait a bit to let the circuit stabilize // wait a bit to let the circuit stabilize
delay(100); delay(50);
// get analog input value // get analog input value
soilmoisture = analogRead(PINanalog); // get values 10 times and get the middle for more precise data
for(byte i = 0; i < 10 ; i++) {
soilmoisture = soilmoisture + analogRead(PINanalog);
}
soilmoisture = soilmoisture / 10;
// disable Vcc for the sensor to release analog pin // disable Vcc for the sensor to release analog pin
digitalWrite(PINsoilmoisture, LOW); digitalWrite(PINsoilmoisture, LOW);
break; break;