lyre liu / Mbed 2 deprecated project1

Dependencies:   mbed

Revision:
11:261f1ba05668
Parent:
10:0457bb95d21e
Child:
12:623f562fc3db
diff -r 0457bb95d21e -r 261f1ba05668 main.cpp
--- a/main.cpp	Tue Mar 08 10:01:44 2016 +0000
+++ b/main.cpp	Tue Mar 08 13:46:42 2016 +0000
@@ -7,6 +7,7 @@
 
 AnalogIn voltage(p20);              // AnalogIn is a class of anlog input, p20 is the pin you use for anlog input,
                                     // You can change the pin from pin15 to pin20
+float voltage_measure;
 Serial pc(USBTX, USBRX);            // Communicate with PC through the serial
 
 DigitalOut high_pin(p5);            //test pin, p5 is the high level pin
@@ -29,7 +30,8 @@
     
     while(1)
     {
-        MassCompute(voltage.read());  
+        voltage_measure = voltage.read();
+        MassCompute(voltage_measure);  
         SerialTransmit();
         //pc.printf("%d",test);
         wait_ms(SAMPLE_TIME);               //Wait for 100ms, this is the sample time.
@@ -54,20 +56,23 @@
 
 void SerialTransmit(void)
 {   
-    unsigned char start,end,test1,test2;
+    unsigned char start,end,voltage_high,voltage_low;
     start = 0xfe;
     end   = 0xff;
-    //test1 = '%';
-    //test2 = '$';
+
+
     if(mass>3)
         mass =3;
     mass_trans_low = (unsigned char)(mass*10000);
     mass_trans_high = (unsigned char)(mass*10000)>>8;
     
+    voltage_high = (unsigned char)(voltage_measure*10000)>>8;
+    voltage_low  = (unsigned char)(voltage_measure*10000);
+    
     pc.printf("%c",start);
-    pc.printf("%c",mass_trans_high);
-    pc.printf("%c",mass_trans_low);
-    //pc.printf("%c",test1);
-    //pc.printf("%c",test2);
+    //pc.printf("%c",mass_trans_high);
+    //pc.printf("%c",mass_trans_low);
+    pc.printf("%c",voltage_high);
+    pc.printf("%c",voltage_low);
     pc.printf("%c",end);
 }
\ No newline at end of file