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: BMP280
Revision 8:dbb57b4d5ba4, committed 2018-01-04
- Comitter:
- Swaggie
- Date:
- Thu Jan 04 19:32:30 2018 +0000
- Parent:
- 7:bf9f92ff02e8
- Child:
- 9:ac5673cca703
- Child:
- 14:1fb1354ac27c
- Commit message:
- Corrected a few compile errors in sampling code.
Changed in this revision
--- a/BME280.lib Thu Jan 04 17:34:57 2018 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://developer.mbed.org/users/MACRUM/code/BME280/#c1f1647004c4
--- a/Sampling.cpp Thu Jan 04 17:34:57 2018 +0000
+++ b/Sampling.cpp Thu Jan 04 19:32:30 2018 +0000
@@ -1,17 +1,6 @@
#include "Sampling.h"
#include "mbed.h"
-
-//Thread Sync Tools
-Mutex tempReadingsLock;
-Mutex presReadingsLock;
-Mutex LDRReadingsLock;
-Mutex timeReadingsLock;
-
-//Buffers
-float tempReadings[BUFFERSIZE];
-float presReadings[BUFFERSIZE];
-float LDRReadings[BUFFERSIZE];
-float timeReadings[BUFFERSIZE];
+#include "rtos.h"
//Index
unsigned short newestIndex = BUFFERSIZE-1;
@@ -20,18 +9,17 @@
bool firstSample = true;
//Hardware
-#ifdef BME
-BME280 sensor(D14, D15);
-#else
BMP280 sensor(D14, D15);
-#endif
-AnalogIn LDRSensor(PA_1); //Check this is the correct pin
+AnalogIn LDRSensor(PA_0);
+DigitalOut SamplingLED(LED1);
void SampleTimerISR(void)
{
//Flag Threads
t1.signal_set(1);
t2.signal_set(1);
+ SamplingLED = 1;
+ SampleLEDTimeout.attach(&FlipSamplingLED,1); //To turn LED off
}
void ConfigThreadsAndIR(void)
@@ -39,10 +27,10 @@
NewEnvSample = false; //Reset
NewLDRSample = false; //Reset
- t1.start(ThreadSampleEnvSensor);
- t2.start(ThreadSampleLDR);
+ t1.start(&ThreadSampleEnvSensor);
+ t2.start(&ThreadSampleLDR);
- sampleRate.attach(SampleTimerISR, 15); //15 second interval
+ sampleRate.attach(&SampleTimerISR, 15); //15 second interval
}
void AddTempSample(float temp)
@@ -56,7 +44,7 @@
{
presReadingsLock.lock(); //Take the key
presReadings[newestIndex+1] = pres; //Add to register
- presReadingsLock.unclock(); //Release the key
+ presReadingsLock.unlock(); //Release the key
}
void ThreadSampleEnvSensor(void)
@@ -75,7 +63,7 @@
void AddLDRSample(float LDRval)
{
LDRReadingsLock.lock(); //Take the key
- LDRReadings[newestIndex+1] = LDR; //Add the sample after the most recent
+ LDRReadings[newestIndex+1] = LDRval; //Add the sample after the most recent
LDRReadingsLock.unlock(); // Release the key
}
@@ -84,7 +72,7 @@
while (true) {
Thread::signal_wait(1); //Wait for signal 1
//get readings
- float LDRval = LDRSensor.value(); //Read the analogue pin value
+ float LDRval = LDRSensor; //Read the analogue pin value
//get time function
AddLDRSample(LDRval);
//add time sample
@@ -106,3 +94,8 @@
}
}
}
+
+void FlipSamplingLED(void)
+{
+ SamplingLED = 0;
+}
--- a/Sampling.h Thu Jan 04 17:34:57 2018 +0000 +++ b/Sampling.h Thu Jan 04 19:32:30 2018 +0000 @@ -2,22 +2,11 @@ #define __Sampling__ #include "mbed.h" - -#ifdef BME -#include "BME280.h" -#else #include "BMP280.h" -#endif +#include "rtos.h" #define BUFFERSIZE 120 -#ifdef BME -extern BME280 sensor; -#else -extern BMP280 sensor; -#endif - -AnalogIn LDRSensor; //Input pin for LDR //Thread Sync Tools Mutex tempReadingsLock; @@ -31,20 +20,22 @@ float LDRReadings[BUFFERSIZE]; float timeReadings[BUFFERSIZE]; -unsigned short newestIndex; +extern unsigned short newestIndex; //Position in the buffer of the newest sample -unsigned short oldestIndex; +extern unsigned short oldestIndex; //Position in the buffer of the oldest sample -bool firstSample; +extern bool firstSample; //Used to indicate this is the first sample to be taken. used in IncrementIndex func Thread t1; //Sample Enviromental Sensor Thread t2; //Sample LDR Sensor Ticker sampleRate; -AnalogIn LDR(A13); //LDR Pin -DigitalOut SamplingLED(LED1); //Onboard LED showing when a sample happens +Timeout SampleLEDTimeout; +extern BMP280 sensor; +extern AnalogIn LDRSensor; //Input pin for LDR +extern DigitalOut SamplingLED; //Onboard LED showing when a sample happens /*These can be deleted I think extern float fLatestTemp; @@ -83,4 +74,7 @@ //Called after samples are added. Increments the index and moves the oldest //along if necessary +void FlipSamplingLED(void); +//Called by timeout, turns of LED + #endif \ No newline at end of file