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.
input_driver.cpp.orig
- Committer:
- bky
- Date:
- 2020-11-30
- Revision:
- 7:12eed49f95fc
File content as of revision 7:12eed49f95fc:
# 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;
}
