Working code for pc app 12/01/2018 commit
Dependencies: mbed MS5607 mbed-dsp
Fork of Turrentine_Code by
Diff: main.cpp
- Revision:
- 5:44cfc3e81d1c
- Parent:
- 4:d4804771134a
- Child:
- 7:1a4bbff83b4d
--- a/main.cpp Thu Jan 25 10:20:46 2018 +0000 +++ b/main.cpp Thu Jan 25 13:25:08 2018 +0000 @@ -13,15 +13,16 @@ #define REGRESSION_SLOPE 53.77986f //from Excel fit to test data #define REGRESSION_INTERCEPT -80.07f -float thresholds[] = {10.f, 30.f, 50.f, 70.f}; //estimated t90 thresholds to turn on LEDs +float thresholds[] = {0.f, 10.f, 30.f, 50.f, 70.f}; //estimated t90 thresholds to turn on LEDs //mbed class def Serial pc(USBTX, USBRX); // tx, rx MS5607SPI pressure_sensor(p5, p6, p7, p8); // mosi, miso, sclk, cs -BusOut leds(LED1, LED2, LED3, LED4); +#define N_LEDS 4 +PwmOut leds[N_LEDS] = {LED1, LED2, LED3, LED4}; -PwmOut motor(p26); +DigitalOut motor(p26); Timer sample_timer; Timer iter_timer; @@ -51,11 +52,10 @@ //Configure motor PWM motor = 0; - motor.period_ms(10); printf("Pump On\n"); //turn pump on - motor.write(duty); + motor = duty; printf("Start loop\n"); int iter_counter = 0; //Iteration counter @@ -130,11 +130,17 @@ //Output iteration data iter_counter++; - printf("%5d %5d %10.0f %4d %10.5e %3.0f\n", 1000000 / (sample_timer.read_us() / N_SAMPLES), iter_timer.read_ms() / iter_counter, f_data[0] / N_SAMPLES, max_mag_i, sum, t90); + printf("%5d %5d %10.0f %4d %10.5e %4.1f\n", 1000000 / (sample_timer.read_us() / N_SAMPLES), iter_timer.read_ms() / iter_counter, f_data[0] / N_SAMPLES, max_mag_i, sum, t90); //Set LEDs based on thresholds - for(int i = 0; i < 4; i++) { - leds[i] = t90 >= thresholds[i]; + for(int i = 0; i < N_LEDS; i++) { + leds[i] = 0; + + if(t90 >= thresholds[i + 1]) { + leds[i] = 1; + } else if(i < (N_LEDS - 1)) { + leds[i] = (t90 - thresholds[i]) / (thresholds[i + 1] - thresholds[i]); + } } //break;