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: input_driver.cpp.orig
- Revision:
- 7:12eed49f95fc
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/input_driver.cpp.orig Mon Nov 30 22:34:25 2020 +0000
@@ -0,0 +1,26 @@
+# define LIGHT_SENSOR_PIN p15
+
+#include "mbed.h"
+# include <stdbool.h>
+
+AnalogIn lightSensorVoltage(LIGHT_SENSOR_PIN);
+
+bool flashDetected = false;
+
+int main() {
+ int voltage0 = 0; // previous voltage
+ int voltage1 = 0; // previous-previous voltage
+
+ while(1) {
+ // detects if there was in an inflection point in the voltage, where it went from increasing, to decreasing
+ flashDetected = (voltage1 < voltage0) && (voltage0 > lightSensorVoltage);
+
+ // update stored values
+ voltage1 = voltage0;
+ voltage0 = lightSensorVoltage;
+ }
+}
+
+bool getFlashDetected() {
+ return flashDetected;
+}
\ No newline at end of file
