Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Fork of Amaldi_7_Exercise_TempSensor by
Revision 3:dca542c609c9, committed 2018-06-18
- Comitter:
- MarcoBattista
- Date:
- Mon Jun 18 12:30:29 2018 +0000
- Parent:
- 2:dbaf3140560a
- Commit message:
- SENSORE TEMP
Changed in this revision
| TempSensor.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/TempSensor.cpp Sat May 12 12:44:47 2018 +0000
+++ b/TempSensor.cpp Mon Jun 18 12:30:29 2018 +0000
@@ -4,9 +4,9 @@
// numero di acqusizioni su cui effettuare la media della temperatura
#define NUMSAMPLE 300
-AnalogIn InWave(PC_0);
+AnalogIn InWave(PA_0);
Serial pc(USBTX, USBRX);
-
+DigitalOut myRele(PC_3);
// Output LED di diagnostica
DigitalOut led1(LED1); // verde
@@ -25,11 +25,11 @@
volatile bool bStop;
// valore letto dall'ADC e corrispondente in tensione
-volatile unsigned short usReadADC;
+volatile unsigned short usReadADCLux;
volatile float fReadVoltage;
// valore di temperatura letto dall'ADC
-volatile float fTemp;
+volatile float fLux;
//***************************
// Acquisizione da ADC
@@ -39,7 +39,7 @@
// indice per i cicli
int nIndex;
// valore medio della temperatura su NUMACQUISISIONI acquisizioni
- float fAvgTemp;
+ float fAvgLux;
// se è stato inviato il comando Stop, non fare niente fino a nuovo comando
if(bStop)
@@ -48,65 +48,37 @@
else // se non è stato inviato il comando di bStop continua
{
// inizializza il valore medio della temperatura
- fAvgTemp=0.0;
+ fAvgLux=0.0;
for(nIndex=0; nIndex < NUMSAMPLE; nIndex++)
{
// acquisisce dato da ADC
- usReadADC = InWave.read_u16();
- fReadVoltage=(usReadADC*3.3)/65535.0; // converte in Volt il valore numerico letto dall'ADC
+ usReadADCLux = InWave.read_u16();
+ fReadVoltage=(usReadADCLux*32767)/1.75; // converte in Volt il valore numerico letto dall'ADC
//fReadVoltage=InWave.read(); // acquisisce il valore dall'ADC come valore di tensione in volt
- fTemp= ((fReadVoltage-0.25)*100.0)/(3.05-0.25); //applica la formula della retta tra i valori minimo e massimo del sensore
- fAvgTemp+=fTemp;
+ fLux=fReadVoltage;
+ fAvgLux+=fLux;
}
// calcola valore medio su NUMSAMPLE acquisizioni
- fAvgTemp/= NUMSAMPLE;
+ fAvgLux/= NUMSAMPLE;
- // accendi LED in base a superamento soglie
- if (fAvgTemp <= 30.0)
+ if(fAvgLux < 0.9)
{
- // accendi LED Blu sotto i 28°
- led1=0;
- led2=1;
- led3=0;
+ // accendi il relè sotto i 0.9 lux
+ myRele =0x01 ;
}
else
{
- if(fAvgTemp >= 32.0)
- {
- // accendi LED Rosso sopra i 32°
- led1=0;
- led2=0;
- led3=1;
- }
- else
- {
- // accendi LED verde tra 28 e 30
- led1=1;
- led2=0;
- led3=0;
- }
+ myRele =0x00 ;
}
-
-
-
-
- // invia il dato al PC
- //pc.printf("\n\r--- Voltage= %.1f [Volt]; Temperature= %.1f [Celsius] ---\n\r", fReadVoltage, fTemp);
- pc.printf("\n\r--- Digital= %d [Volt]; Temperature= %.2f [Celsius] ---\n\r", usReadADC, fTemp);
-
-
-
- /*
- // prepara il pacchetto di dati acquisiti da restituire al PC
- caTxPacket[nSampleInCount]= (char)(usReadADC&0xFF);
- //+++caTxPacket[nSampleInCount]= 'a';
- nSampleInCount++;
- caTxPacket[nSampleInCount] = (char)((usReadADC>>8)&0xFF);
- //++++caTxPacket[nSampleInCount]= 'b';
- */
-
+ }
+
+ pc.printf("\n\r--- Digital= %d [Volt]; Luminosita'= %.2f [Lux] ---\n\r", usReadADCLux, fLux);
+
+
+
+
+ // invia il dato al PC
}
-}
@@ -119,17 +91,17 @@
// periodo di campionamento
int nDeltaT;
-
+
// configura velocità della comunicazione seriale su USB-VirtualCom e invia messaggio di benvenuto
pc.baud(921600); //921600 bps
// messaggio di benvenuto
- pc.printf("\r\nHallo Amaldi Students - Exercise 7 \r\n");
- pc.printf("\r\n*** Bluetooth Temp Acquisition ***\r\n");
+ pc.printf("\r\nHey Bro! \r\n");
+ // pc.printf("\r\n*** Bluetooth Temp Acquisition ***\r\n");
// inizializza variabili
bStop=true;
- // test dei LED
+ /* test dei LED
led1=1; //Verde
wait_ms(1000);
led1=0;
@@ -139,11 +111,13 @@
led3=1; //Rosso
wait_ms(1000);
led3=0;
-
+ */
while(true)
{
+
+
// verifica se è arrivato un carattere dalla seriale del PC
if(pc.readable())
{
@@ -161,22 +135,7 @@
nDeltaT = nReadChar; // sampling Period in sec
pc.printf("\n\r--- Acquisition Started DeltaT = %c ---\n\r", cReadChar);
SamplingTicker.attach(&Sampling,nDeltaT);
- }
-
+ }
} //lettura da pc
} // while(true)
-}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+}
\ No newline at end of file
