Modifs mineures

This commit is contained in:
Grouch 2018-03-20 10:36:21 +01:00
parent f20197f5a9
commit 03177cd336
1 changed files with 27 additions and 11 deletions

View File

@ -1,10 +1,9 @@
//#include <TimerOne.h>
#include <SPI.h>
#include <SD.h>
#include <SparkFun_ADXL345.h>
#include <SoftwareSerial.h>
#include <MsTimer2.h>
//----------------------------------------------------------------------------------
// CONSTANTES
//----------------------------------------------------------------------------------
@ -27,8 +26,9 @@ SoftwareSerial BT(PIN_BT_RX,PIN_BT_TX); // BLUETOOTH
ADXL345 adxl = ADXL345(); // Capteur ADXL
File dataFile; // Fichier sur carte SD
String dataString = ""; // String courante à écrire
unsigned long pm_flush; // Précédent millis() pour flush
unsigned long cm; // millis() courant
unsigned long pm_flush = 0; // Précédent millis() pour flush
unsigned long cm = 0; // millis() courant
unsigned long t_zero = 0;
bool flag_run = false; // Flag acquisition en route
bool flag = false; // Flag mesure faite
int x,y,z; // Valeurs ADXL
@ -38,7 +38,7 @@ int x,y,z; // Valeurs ADXL
//----------------------------------------------------------------------------------
bool Voie_ON[]= { // Voies actives
true, true, true, true, true, true};
unsigned long T = 500; // Période acquisition µs
unsigned long T = 500; // Période acquisition µs
unsigned long T_FLUSH = 2000; // Période écriture fichier ms
//----------------------------------------------------------------------------------
@ -46,14 +46,15 @@ unsigned long T_FLUSH = 2000; // Période écriture f
//----------------------------------------------------------------------------------
void mesure(){
dataString = "";
unsigned long cm_mesure = millis();
// 0 = millis
// 1 = RTC
// 1 = temps passé
// 2,3,4 = X,Y,Z
// 5 = TC
if (Voie_ON[0]) {dataString += String(millis());}
if (Voie_ON[1]) {/*RTC!!*/}
if (Voie_ON[0]) {dataString += String(cm_mesure);}
if (Voie_ON[1]) {dataString += " " + String(cm_mesure-t_zero);}
if (Voie_ON[2] || Voie_ON[3] || Voie_ON[4]){
if (Voie_ON[2]) {dataString += " " + String(x);}
if (Voie_ON[3]) {dataString += " " + String(y);}
@ -97,7 +98,7 @@ void setup() {
dataFile = SD.open("datalog.txt", FILE_WRITE);
menu();
MsTimer2::set(T, mesure); // 500ms period
MsTimer2::set(T, mesure);
MsTimer2::stop();
}
@ -123,13 +124,25 @@ double readTC() {
{return NAN;}
v >>= 3; // The lower three bits (0,1,2) are discarded status bits
return v*0.25; // The remaining bits are the number of 0.25 degree (C) counts
}
void config(){
affich(CONFIG);
affich(String("Période acquisition [" + String(T) + "]"));
T=input(T);
affich(String("T = " + String(T)));
menu();
}
long input(long x){
long in = 0;
while((Serial.available()==0) && (BT.available()==0)){}
if (Serial.available()>0) {in=Serial.parseInt();}
if ( BT.available()>0) { in=BT.parseInt();}
if (in>0){return in;}else{return x;}
}
void affich(String x){
@ -160,8 +173,11 @@ void loop() {
Serial.println(START);
BT.println(START);
flag_run = true;
MsTimer2::set(T, mesure);
MsTimer2::set(T-1, mesure);
MsTimer2::start();
t_zero = millis();
if (Voie_ON[2] || Voie_ON[3] || Voie_ON[4]){adxl.readAccel(&x, &y, &z);}
mesure();
}
if (flag_run && in == 50) {
Serial.println(STOP);