Skip to content

Commit

Permalink
MAJIOR UPDATE TO 13
Browse files Browse the repository at this point in the history
CORRETTO FINALMENTE IL CALCOLO DELL'ASSORBANZA E DELLA TRAMITTANZA!!!!! Ora non va più in overflow e riesco perfino a gestire i decimali (sia per l'LCD che per la seriale separatamente per entrambe le variabili).
Sistemate alcune righe di debug per la porta seriale.
Corretta la posizione della riga di assegnazione MIN_REPLICATES in quanto scrivevo la variabile nReplicates prima di modificarla...

Fix e aggiustamenti minori
  • Loading branch information
massimofrassetto committed Feb 4, 2020
1 parent 089c9c4 commit dea40bd
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 34 deletions.
7 changes: 6 additions & 1 deletion Spear riscritto/Spear_fixed/CONSTANTS.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define COSTANTS.h

#define MODEL_VERSION 1.0
#define FIRMWARE_VERSION 12
#define FIRMWARE_VERSION 13

#define SERIAL_BAUDRATE 115200

Expand Down Expand Up @@ -61,5 +61,10 @@
#define SPECTRALIMIT_HIGH 780
#define MIN_REPLICATES 5

#define DECIMAL_LCD_TRASMITTANCE 6
#define DECIMAL_SERIAL_TRASMITTANCE 8
#define DECIMAL_LCD_ABSORBANCE 6
#define DECIMAL_SERIAL_ABSORBANCE 8


#endif
10 changes: 5 additions & 5 deletions Spear riscritto/Spear_fixed/FUNCTIONS.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ void tslSensorChecking (void){
lcd.clear();
lcd.setCursor(0, 0); lcd.print("TSL2591");
lcd.setCursor(0, 1); lcd.print("Checking...");
delay(1000);
delay(500);
if (tsl.begin()){
lcd.clear();
lcd.setCursor(0, 0); lcd.print("TSL2591 Sensor");
Expand Down Expand Up @@ -96,14 +96,14 @@ void gratingMotorChecking (const int sensMotCheckPin, const int piezoCheckPin){
lcd.clear();
lcd.setCursor(0, 0); lcd.print("Motor Setted!");
lcd.setCursor(0, 1); lcd.print("Dgr.= 0'");
delay(1000);
delay(500);
}

void SDCardChecking (const int chipSel){
lcd.clear();
lcd.setCursor(0, 0); lcd.print("Initializing");
lcd.setCursor(0, 1); lcd.print("SD card...");
delay(2000);
delay(500);
if (!SD.begin(chipSel)) {
printWiringError(PIN_PIEZO);
delay(2500);
Expand All @@ -112,7 +112,7 @@ void SDCardChecking (const int chipSel){
lcd.clear();
lcd.setCursor(0, 0); lcd.print("Initialization");
lcd.setCursor(0, 1); lcd.print("DONE!!!");
delay(3000);
delay(500);
}

void lampChecking (const int lampSensPin, const int lampStatePin, int* lampState, const int piezoLCPin){
Expand Down Expand Up @@ -165,7 +165,7 @@ int simpleRead(void){
//uint16_t x = tsl.getLuminosity(TSL2561_FULLSPECTRUM);
//uint16_t x = tsl.getLuminosity(TSL2561_INFRARED);

Serial.println(x, DEC);
Serial.print(">> "); Serial.println(x, DEC); //rimuovere dal di qui
readsVal=x;
}

Expand Down
59 changes: 31 additions & 28 deletions Spear riscritto/Spear_fixed/Spear_fixed.ino
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ int nReplicates;
int nReads;
int readsVal=0;
int sumReadsVal=0;
long sumBackgroundReadsVal=0;
long sumSampleReadsVal=0;
float sumBackgroundReadsVal=0;
float sumSampleReadsVal=0;

int backVal=LOW;
int nextVal=LOW;
Expand All @@ -79,8 +79,9 @@ void setup(void){
Serial.println("=====================================");
Serial.println("========== STARTING SYSTEM ==========");
Serial.println("=====================================");
Serial.print("========== Model:\t"); Serial.println(MODEL_VERSION);
Serial.print("========== Firmware:\t"); Serial.println(FIRMWARE_VERSION);
Serial.print("========== Model:\t"); Serial.println(MODEL_VERSION);
Serial.print("========== Firmware:\t"); Serial.println(FIRMWARE_VERSION);
Serial.println("=====================================");
#endif
AFMS.begin();
myMotor->setSpeed(MOTOR_SPEED_RPM);
Expand Down Expand Up @@ -135,6 +136,7 @@ void setup(void){
gratingMotorCurrentSteps=0;
#ifdef DEBUG
Serial.println("======= Initialization COMPLETED =======");
Serial.print("================ "); Serial.print(millis()/1000); Serial.println("s =================");
#endif
lcd.clear();
lcd.setCursor(0, 0); lcd.print("Instrument");
Expand Down Expand Up @@ -207,7 +209,7 @@ void loop(void){
delay(200);
#ifdef DEBUG
Serial.print(">> Mode Selected: "); Serial.print(indexAnalysisMode); Serial.print(" - "); Serial.println(analysisModeLcdString[indexAnalysisMode]);
Serial.println("Waiting confirm...");
Serial.println(">> Waiting confirm...");
#endif
switch(indexAnalysisMode){
case(ANALYSISMODE_SIMPLEREAD):{
Expand All @@ -219,15 +221,15 @@ void loop(void){
backVal=digitalRead(PIN_BUTTON_BACK);
if(okVal){
#ifdef DEBUG
Serial.println("Simple Read Selected!");
Serial.println(">> Simple Read Selected!");
#endif
okVal=LOW;
delay(100);
lcd.clear();
lcd.setCursor(0, 0); lcd.print("Lambda (nm): ");
lcd.setCursor(0, 1); lcd.print("Set Val: ");
#ifdef DEBUG
Serial.print(">> Lambda requested:\t");
Serial.print(">> Lambda requested:\t\t");
#endif
keyPadString="";
while(!okVal){
Expand Down Expand Up @@ -258,10 +260,10 @@ void loop(void){
Serial.print(">> Lambda Corrected to ["); Serial.print(lambdaCorrected); Serial.print("] couse it's lower then the lower limit of "); Serial.print(SPECTRALIMIT_LOW); Serial.println("nm.");
}
else if (lambdaCorrected>lambdaSelected){
Serial.print(">> Lambda Corrected to ["); Serial.print(lambdaCorrected); Serial.print("] couse it's greater then the higher limit of "); Serial.print(SPECTRALIMIT_LOW); Serial.println("nm.");
Serial.print(">> Lambda Corrected to ["); Serial.print(lambdaCorrected); Serial.print("] couse it's greater then the higher limit of "); Serial.print(SPECTRALIMIT_HIGH); Serial.println("nm.");
}
else{
Serial.println(">> Lambda Acceptded.");
Serial.println(">> Lambda Acceptded!!");
}
#endif
lcd.clear();
Expand All @@ -286,21 +288,23 @@ void loop(void){
}
okVal=LOW;
#ifdef DEBUG
Serial.println();
Serial.println("nm.");
#endif
nReplicates=keyPadString.toInt();
if(nReplicates<MIN_REPLICATES){
nReplicates=MIN_REPLICATES;
#ifdef DEBUG
Serial.print(">> Replicates Corrected to ["); Serial.print(nReplicates); Serial.print("] couse it's lower then the lower limit of "); Serial.print(MIN_REPLICATES); Serial.println("nm.");
Serial.print(">> Replicates Corrected to ["); Serial.print(nReplicates); Serial.print("] couse it's lower then the lower limit of "); Serial.print(MIN_REPLICATES); Serial.println(".");
#endif
nReplicates=MIN_REPLICATES;
}
else{
#ifdef DEBUG
Serial.println(">> Replicates Acceptded.");
Serial.println(">> Replicates Acceptded!!");
#endif
}
//delay(1000);
#ifdef DEBUG
Serial.println(">> Positioning motor...");
#endif
lcd.clear();
lcd.setCursor(0, 0); lcd.print("Replicates: " + String(nReplicates));
lcd.setCursor(0, 1); lcd.print("Pos.ing motor...");
Expand Down Expand Up @@ -345,7 +349,7 @@ void loop(void){
if(okVal){
okVal=LOW;
#ifdef DEBUG
Serial.println(">> Reading blank...");
Serial.println(">> Reading Sample...");
#endif
lcd.clear();
lcd.setCursor(0, 0); lcd.print("Reading...");
Expand All @@ -363,25 +367,24 @@ void loop(void){
#ifdef DEBUG
Serial.println(">> Sample reads done! Calculating results...");
#endif
long iSource=((sumBackgroundReadsVal)/(nReplicates));
long iSample=((sumSampleReadsVal)/(nReplicates));
long trasmittance=(1000*((iSample)/(iSource)));
long absorbance=log10(1/((iSample)/(iSource)))*1000;
long Abs=(log10(1/((sumSampleReadsVal)/(nReplicates)/(sumBackgroundReadsVal)/(nReplicates))))*1000;

float iSource=sumBackgroundReadsVal/(float)nReplicates;
float iSample=((sumSampleReadsVal/(float)nReplicates));
float trasmittance=iSample/iSource;
float absorbance=log10(1/((((sumSampleReadsVal/(float)nReplicates)/(sumBackgroundReadsVal/(float)nReplicates))))); //verificare il 1000
//float Abs=log10(1/(iSample/iSource))*1000;
lcd.clear();
lcd.setCursor(0, 0); lcd.print("Abs Sample:");
lcd.setCursor(0, 1); lcd.print(String(Abs));
lcd.setCursor(0, 1); lcd.print(String(absorbance,DECIMAL_LCD_ABSORBANCE));
#ifdef DEBUG
Serial.println(">> [---------------------------------------------------]");
Serial.print(">> [ Numeber of reads:\t"); Serial.println(nReplicates);
Serial.print(">> [ Number of reads:\t\t"); Serial.println(nReplicates);
Serial.print(">> [ Background Average:\t"); Serial.println((sumBackgroundReadsVal)/(nReplicates));
Serial.print(">> [ Sample Average:\t\t"); Serial.println((sumSampleReadsVal)/(nReplicates));
Serial.print(">> [ iSource:\t\t\t\t"); Serial.println(iSource);
Serial.print(">> [ iSample:\t\t\t\t"); Serial.println(iSample);
Serial.print(">> [ Trasmittance:\t\t\t"); Serial.println(trasmittance);
Serial.print(">> [ Absorbance:\t\t\t\t"); Serial.println(absorbance);
Serial.print(">> [ Abs:\t\t\t\t\t"); Serial.println(Abs);
//Serial.print(">> [ iSource:\t\t\t"); Serial.println(iSource);
//Serial.print(">> [ iSample:\t\t\t"); Serial.println(iSample);
Serial.print(">> [ Trasmittance:\t\t"); Serial.println(trasmittance,DECIMAL_SERIAL_TRASMITTANCE);
Serial.print(">> [ Absorbance:\t\t"); Serial.println(absorbance,DECIMAL_SERIAL_ABSORBANCE);
//Serial.print(">> [ Abs:\t\t\t"); Serial.print(Abs); Serial.println("*10^-3.");
Serial.println(">> [---------------------------------------------------]");
#endif
}
Expand Down

0 comments on commit dea40bd

Please sign in to comment.