mirror of
https://gitlab.com/Luci_/arduino-photometrics.git
synced 2026-04-03 11:35:37 +02:00
104 lines
3 KiB
C++
Executable file
104 lines
3 KiB
C++
Executable file
#include <Arduino.h>
|
|
#include <Wire.h>
|
|
#include <DS3231.h>
|
|
|
|
#include "photoresistance_ohm_retrieval.h"
|
|
#include "myFunction.h"
|
|
#include "sensormanager.h"
|
|
#include "traitement.h"
|
|
#include "storage_interface.h"
|
|
|
|
const long BAUD_RATE = 9600;
|
|
|
|
int ledPin = 2, decTemp = 4; // nb decimal temperature printing
|
|
const int nbPhotoSensor = 6;
|
|
uint8_t analogPin [nbPhotoSensor] = {A0, A1, A2 ,A3 ,A5 ,A6};
|
|
int32_t min_res [nbPhotoSensor] = {128, 160, 193, 96, 323, 96};
|
|
int32_t max_res [nbPhotoSensor] = {2062273, 5554006, 784809, 4755895, 1939035, 289546};
|
|
bool winter = 1;
|
|
|
|
SensorOhm test[nbPhotoSensor];
|
|
SensorManager s_manager;
|
|
Traitement tr;
|
|
Storage_interface sto_intrf;
|
|
|
|
RTClib myRTC;
|
|
DS3231 Clock;
|
|
|
|
void setup() {
|
|
Wire.begin();
|
|
Serial.begin(BAUD_RATE);
|
|
s_manager.setup(nbPhotoSensor, analogPin);
|
|
}
|
|
|
|
void loop() {
|
|
DateTime now;
|
|
|
|
if (Serial.available()) {
|
|
char commande = Serial.read();
|
|
if (commande == 'T') {
|
|
|
|
unsigned long epoch = Serial.parseInt(); // read epoch
|
|
if (epoch > 1000000000UL) { // sanity check
|
|
// summer or winter time
|
|
if (winter == 1) {
|
|
epoch += 3600;
|
|
}
|
|
Clock.setEpoch(epoch);
|
|
#ifdef DEBUG
|
|
Serial.print("RTC mis à jour avec epoch: ");
|
|
Serial.println(epoch);
|
|
#endif
|
|
}
|
|
while (Serial.available()) Serial.read(); // clean buffer
|
|
|
|
#ifdef DEBUG
|
|
// Just for verification of DS3231 Data
|
|
// check now the data from ESP8266 and DS3231
|
|
// get year
|
|
bool century = false;
|
|
bool h12Flag;
|
|
bool pmFlag;
|
|
now = myRTC.now();
|
|
Serial.print("\n\n");
|
|
Serial.print(" DateTime of DS3231: ");
|
|
Serial.print(Clock.getYear(), DEC);
|
|
Serial.print("-");
|
|
Serial.print(Clock.getMonth(century), DEC);
|
|
Serial.print("-");
|
|
Serial.print(Clock.getDate(), DEC);
|
|
Serial.print(" ");
|
|
Serial.print(Clock.getHour(h12Flag, pmFlag), DEC);
|
|
Serial.print(":");
|
|
Serial.print(Clock.getMinute(), DEC);
|
|
Serial.print(":");
|
|
Serial.print(Clock.getSecond(), DEC);
|
|
Serial.print(" - weekday ");
|
|
Serial.print(Clock.getDoW(), DEC);
|
|
Serial.println();
|
|
#endif
|
|
}else if (commande == 'D'){
|
|
sto_intrf.upload_csv();
|
|
}
|
|
while (Serial.available()) Serial.read(); // clean buffer
|
|
delay(10);
|
|
}
|
|
|
|
#ifdef DEBUG
|
|
printDate(Clock, decTemp);
|
|
s_manager.print_current_res();
|
|
s_manager.print_min_max_res();
|
|
#endif
|
|
|
|
int32_t res_array[nbPhotoSensor]/*, min_array[nbPhotoSensor], max_array[nbPhotoSensor]*/;
|
|
int16_t result[nbPhotoSensor];
|
|
s_manager.get_resistances(res_array, nbPhotoSensor);
|
|
|
|
tr.map_r(min_res, max_res, res_array, result, nbPhotoSensor);
|
|
#ifdef DEBUG
|
|
print_named_tab(result, nbPhotoSensor, "int32_t normalised",(uint8_t) 18);
|
|
#endif
|
|
|
|
delay(2000);
|
|
}
|