abc
Dependencies: mbed-rtos mbed pixy pixy_test
Fork of aUtO_volume_v3 by
Diff: main.cpp
- Revision:
- 4:fe091424b406
- Parent:
- 3:56a1264e43aa
- Child:
- 5:06fa76d9d7bd
diff -r 56a1264e43aa -r fe091424b406 main.cpp --- a/main.cpp Wed Dec 09 02:09:20 2015 +0000 +++ b/main.cpp Thu Dec 10 02:41:42 2015 +0000 @@ -4,6 +4,8 @@ // init board Pixy pixy(Pixy::SPI, p11, p12, p13); Serial pc(USBTX, USBRX); +DigitalOut pin1(p24); +DigitalOut pin2(p25); #if defined(TARGET_LPC1768) Serial blue(p9, p10); // TX, RX @@ -16,9 +18,14 @@ // global vars int num_readings = 0; int total_y = 0; +float result_level = 0; // mL +float result_hourly = 0; // mL/hr +float prev_level = 0; -// funcs +// funcs and threads void get_volume(int i); +void get_hourly(void const *args); +RtosTimer get_hourly_thread(get_hourly, osTimerPeriodic); int main() { @@ -33,6 +40,13 @@ // init pixy pixy.setSerialOutput(&pc); + // start entry pump + pin1 = 1; + pin2 = 0; + + // start hourly thread + get_hourly_thread.start(10000); + while (1) { // get pixy data @@ -48,6 +62,11 @@ } } +void update_display(void const *args) { + result_hourly = (result_level-prev_level)*6 + prev_level = result_level; +} + void get_volume(int y) { // update data @@ -55,13 +74,13 @@ num_readings++; // output results - if (num_readings >= 20) { + if (num_readings >= 10) { float average_y = (float)total_y/num_readings; - float result = -2.0028*average_y + 327.23; + float result_level = -0.2642*average_y + 38.453; // to pc pc.printf("y = %d, num_readings = %d, average = %.2f, mL = %.2f\r\n", y, num_readings, average_y, result); - pc.printf("%.2f\r\n", result); + pc.printf("%.2f %.2f\r\n", result_level, result_hourly); // to bluetooth //blue.printf("y = %d, num_readings = %d, average = %.2f, mL = %.2f\r\n", y, num_readings, average_y, result);