abc

Dependencies:   mbed-rtos mbed pixy pixy_test

Fork of aUtO_volume_v4 by ese519

Revision:
3:56a1264e43aa
Parent:
2:1354ce60c0b9
Child:
4:fe091424b406
--- a/main.cpp	Tue Nov 24 01:26:57 2015 +0000
+++ b/main.cpp	Wed Dec 09 02:09:20 2015 +0000
@@ -5,6 +5,14 @@
 Pixy pixy(Pixy::SPI, p11, p12, p13);
 Serial pc(USBTX, USBRX);
 
+#if   defined(TARGET_LPC1768)
+Serial blue(p9, p10);          // TX, RX
+//Serial blue(p13, p14);         // TX, RX
+#elif defined(TARGET_LPC4330_M4)
+Serial blue(P6_4, P6_5);         // UART0_TX, UART0_RX
+//Serial blue(P2_3, P2_4);         // UART3_TX, UART3_RX
+#endif
+
 // global vars
 int num_readings = 0;
 int total_y = 0;
@@ -14,8 +22,15 @@
 
 int main() {
     
+    // init bluetooth
+    blue.baud(9600);
+    
+    // init pc
+    pc.baud(9600);
+    pc.printf("Bluetooth Start\r\n");
+    pc.printf("ready\n\r");
+    
     // init pixy
-    pc.printf("ready\n\r");
     pixy.setSerialOutput(&pc);
     
     while (1) {
@@ -40,11 +55,18 @@
     num_readings++;
     
     // output results
-    if (num_readings > 30) {
+    if (num_readings >= 20) {
         float average_y = (float)total_y/num_readings;
-        float result = -2.0794*average_y + 351.97;
-        pc.printf("y = %d, num_readings = %d, average = %f, mL = %f\r\n", y, num_readings, average_y, result);
+        float result = -2.0028*average_y + 327.23;
         
+        // 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);
+        
+        // to bluetooth
+        //blue.printf("y = %d, num_readings = %d, average = %.2f, mL = %.2f\r\n", y, num_readings, average_y, result);
+        blue.printf("%.2f\r\n", result);
+
         // reset vars
         num_readings = 0;
         total_y = 0;