Программа считывает показания датчиков и управляет сервомашинками.

Dependencies:   mbed-src

Fork of NUCLEO_BLUENRG by Ostap Ostapsky

Files at this revision

API Documentation at this revision

Comitter:
Sergeev
Date:
Mon Aug 25 09:45:34 2014 +0000
Parent:
0:aa1e012ec210
Commit message:
Final

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Sat Aug 16 11:00:04 2014 +0000
+++ b/main.cpp	Mon Aug 25 09:45:34 2014 +0000
@@ -12,6 +12,9 @@
 SPI_HandleTypeDef SpiHandle;
 
 Serial pc(SERIAL_TX, SERIAL_RX);
+PwmOut mypwm(D2);
+AnalogIn analog_value(A2);
+int flag = 0;
 
 extern volatile uint8_t set_connectable;
 extern volatile int connected;
@@ -37,9 +40,13 @@
     /* Configure the system clock */
     SystemClock_Config();
     
+    mypwm.period_ms(20);
+    //mypwm.pulsewidth_ms(1.5);
+    
     /* Initialize the BlueNRG SPI driver */
     BNRG_SPI_Init();
     
+    
     /* Initialize the BlueNRG HCI */
     HCI_Init();
     
@@ -83,9 +90,37 @@
     /* Set output power level */
     ret = aci_hal_set_tx_power_level(1,4);
     
+    static uint32_t cnt1=0;
+    
     /* Infinite loop */
     while (1)
     {
+        /*
+        for(float offset=0.0; offset<0.001; offset+=0.0001) {
+            mypwm.pulsewidth(0.001 + offset); // servo position determined by a pulsewidth between 1-2ms
+            wait(0.25);
+        }
+        */
+        
+        if (HAL_GetTick() > (cnt1 + 1000))
+        {
+            cnt1=HAL_GetTick();
+            if (flag==0){
+                mypwm.period_ms(20);
+                mypwm.pulsewidth_ms(0.9);
+                flag++;
+                }
+            else if (flag==1){
+                mypwm.period_ms(20);
+                mypwm.pulsewidth_ms(1.5);
+                flag++;
+                }
+            else if (flag==2){
+                mypwm.period_ms(20);
+                mypwm.pulsewidth_ms(2.0);
+                flag=0;
+                }
+        }
         HCI_Process();
         User_Process();
     }
@@ -100,6 +135,7 @@
     static uint32_t cnt;
     static uint8_t acc_en_sent = 0; 
     tHalUint8 data[2];
+    uint8_t* temp;
     //uint8_t data_length;
         
     if(set_connectable){
@@ -134,19 +170,29 @@
         cnt = HAL_GetTick();    
     } 
     
-    if (HAL_GetTick() > (cnt + 2000))
+    if (HAL_GetTick() > (cnt +2000))
     {
         cnt = HAL_GetTick();
         if (connected && acc_en_sent)
         {
+                               
             
+            float sheint = analog_value.read();
+            pc.printf("Light = %f;\n", sheint);
             pc.printf("T = %f; ", calcTmpTarget(readValue(0x25, NULL)));
-            uint8_t* temp = readValue(0x2D, NULL);
+            temp = readValue(0x2D, NULL);
             pc.printf("Ax = %d; Ay = %d; Az = %d  ", (signed char) temp[0], (signed char) temp[1], (signed char) temp[2]);
             temp = readValue(0x38, NULL);
             pc.printf("H = %f; \r\n", calcHumRel(temp));
             
             
+            /*temp = readValue(0x2D, NULL);
+            pc.printf("%d %d \r\n", (signed char) temp[0], (signed char) temp[1]);*/
+            
+            /*pc.printf("%d ", (signed short)calcTmpTarget(readValue(0x25, NULL)));
+            temp = readValue(0x38, NULL);
+            pc.printf("%d \r\n", (signed short)calcHumRel(temp));*/
+            
             //GATT services scan
             /*for (unsigned char j = 1; j < 0x88; j++)
             {