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.
Diff: main.cpp
- Revision:
- 9:b7e8d0372f53
- Parent:
- 8:9f59ef177620
- Child:
- 10:8d86e59fb408
--- a/main.cpp Mon Nov 30 23:42:26 2020 +0000
+++ b/main.cpp Tue Dec 01 00:20:30 2020 +0000
@@ -1,19 +1,41 @@
#include "mbed.h"
-#include "input_driver.h"
-#include "output_driver.h"
+
#include <time.h>
+# include <stdbool.h>
+
+# define LIGHT_SENSOR_PIN p15
+
+
+
+AnalogIn lightSensorVoltage(LIGHT_SENSOR_PIN);
+Serial pc(USBTX, USBRX);
DigitalOut myled(LED1);
+float voltage0 = 0;
+float voltage1 = 0;
+
+bool flashDetected() {
+ bool flashDetected = (voltage1 < voltage0) && (voltage0 > lightSensorVoltage.read());
+
+ // update stored values
+ voltage1 = voltage0;
+ voltage0 = lightSensorVoltage;
+
+ return flashDetected;
+}
+
+void sendFloat(float value) {
+ for (int i=0; i<4; i++)
+ pc.putc(*(((char*) &value)+i));
+}
+
int main() {
//int flashTime = 0;
printf("starting\n");
while(1) {
- printf("%f", getSensorStrength());
- sendFloat((float)getSensorStrength());
- if(getFlashDetected()) {
- printf("flash as %f\n", clock());
- }
+ sendFloat(lightSensorVoltage.read());
wait(0.1);
}
}
+
