app3 prob

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
joGenie
Date:
Tue Feb 11 18:26:23 2014 +0000
Parent:
1:cb05875a0960
Commit message:
Time go;

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r cb05875a0960 -r c25ba89e3581 main.cpp
--- a/main.cpp	Tue Feb 11 15:39:58 2014 +0000
+++ b/main.cpp	Tue Feb 11 18:26:23 2014 +0000
@@ -10,69 +10,62 @@
 DigitalOut led3(LED3);
 DigitalOut led4(LED4);
 
-unsigned long tc_periods[7] = {0};
+unsigned long tc_periods[9] = {0};
 unsigned long period = 0;
 bool type_bit = true;
 int synchrone = 0;
+int count = 0;
 
-string message = "";
-const unsigned long offset = 100;
+bool good = true;
 
-bitset<16> bits(string("0101010101111110"));
+char message[16] = "";
+const unsigned long offset = 200;
+
+bitset<16> bits(string("0101010101101000"));
 
 void readTrame()
 {
-    if (synchrone < 7)
+    if (synchrone < 8)
     {
         tc_periods[synchrone] = LPC_TIM2->CR1 / 2;
         synchrone++;
         
-        if (synchrone == 7)
+        if (synchrone == 8)
         {
             for (int i = 0; i < synchrone; i++)
             {
                period += tc_periods[i]; 
             }
             
-            period = period/7;
+            period = period/8;
         }
     }
     else
-    {
-        unsigned int tc_count = LPC_TIM2->CR1;
-        if (tc_count > (period - offset) && tc_count < (period + offset))
-        {
-            if (type_bit)
-            {
-                led2 = 1;
-                led3 = 0;
-            }
-            else
-            {
-                led3 = 1;
-                led2 = 0;
-            }
-        }
-        else if (tc_count > (period*2 - offset) && tc_count < (period*2 + offset))
+    {   
+        unsigned long tc_count = LPC_TIM2->CR1;
+        if (tc_count > (period*2 - offset) && tc_count < (period*2 + offset))
         {
             type_bit = !type_bit;
-            led4 = 1;
+            good = true;
+            
             if (type_bit)
-            {
-                led2 = 1;
-                led3 = 0;
-            }
+                message[count] = '1';
             else
-            {
-                led3 = 1;
-                led2 = 0;
-            }
+                message[count] = '0';
+                
+            count++;
         }
         
-        /*if (type_bit)
-            message += "1";
-        else
-            message += "0";*/
+        good = !good;
+        if (good)
+        {
+            if (type_bit)
+                message[count] = '1';
+            else
+                message[count] = '0';
+                
+            count++;
+        }
     }
     
     if (led1 == 0)
@@ -86,9 +79,9 @@
 
 void sendTrame(std::bitset<16> bit)
 {
-    for (int a = 15; a > 0; a--)
+    for (int a = 1; a <= bit.size(); a++)
     {
-        if (bit.test(a))
+        if (bit.test(bit.size() - a))
         {
             LPC_PWM1->MR1 = SystemCoreClock/2;
             LPC_PWM1->MR2 = 1;
@@ -106,14 +99,14 @@
     
     LPC_PWM1->TCR = 0x0;
     
-    pc.printf("%s\n", message.c_str());
+    pc.printf("%s\n", message);
     
     for ( int i = 0; i < 8; i++)
     {
         pc.printf("%d : \t", tc_periods[i]);
     }
     
-    pc.printf("\n");
+    pc.printf("\n%d\n", count);
 }
 
 void send(void const *args)