Brendon Ky / Mbed 2 deprecated cs_335_speedometer

Dependencies:   mbed mbed-rtos

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;
}