v2

Dependencies:   BLE_API mbed DOOR

Fork of DOOR by Aura-Tech Solutions

Revision:
70:08932e600a5e
Parent:
69:bc2f5bfe5e33
--- a/main.cpp	Mon Nov 16 17:05:52 2015 +0000
+++ b/main.cpp	Mon Nov 16 23:25:36 2015 +0000
@@ -42,7 +42,7 @@
                         0xA1, 0x2F, 0x17, 0xD1, 0xAD, 0x07, 0xA9, 0x62
                        };
 uint16_t majorNumber = 1122;
-uint16_t minorNumber = 3345;
+uint16_t minorNumber = 3346;
 uint16_t txPower = 0xC8;
 
 
@@ -68,27 +68,26 @@
 const uint8_t bA9_id  = 0x39;
 const uint8_t bA0_id  = 0x30;
 
+int triger_base = 0;
+int sense_base = 0;
 
-PinName b1_p        = P0_4;
-PinName b2_p        = P0_5;
-PinName b3_p        = P0_9;
-PinName b4_p        = P0_10;
+AnalogIn   pin_sense_an  = P0_5;
+PinName pin_sense        = P0_5;
+PinName pin_triger       = P0_10;
 
 
 //setup led
 DigitalOut led1(P0_19);
 
-//setup digital outs
-
-DigitalOut b1(b1_p);
-DigitalOut b2(b2_p);
-DigitalOut b3(b3_p);
-DigitalOut b4(b4_p);
+//setup digital input/output
+DigitalOut triger(pin_triger);
+DigitalIn sensor(pin_sense);
 
 
 void disconnectionCallback(Gap::Handle_t handle, Gap::DisconnectionReason_t reason);
 void onDataWritten(const GattCharacteristicWriteCBParams *params);
 int flip(char value);
+void blinky(void);
 void testAll(void);
 void disconnectionCallback(Gap::Handle_t handle, Gap::DisconnectionReason_t reason)
 {
@@ -106,7 +105,6 @@
             led1 = 1;
     }*/
     
-    flip(params->data[0]);
 
 }
 
@@ -115,10 +113,9 @@
     /* initialize stuff */
     led1 = 1;
     
-    b1 = 0;
-    b2 = 1;
-    b3 = 1;
-    b4 = 1;
+    triger = triger_base = 0;
+    sense_base = sensor.read();
+
 
 
 
@@ -136,8 +133,18 @@
     ble.setAdvertisingInterval(1000); /* 1000ms. */
     ble.startAdvertising();
 
-    while(1) {
-        ble.waitForEvent(); // allows or low power operation
+    while(1)
+    {
+        //ble.waitForEvent(); // allows or low power operation
+        if(sensor.read() == !sense_base)
+        //if(pin_sense_an > 2.5f)
+        {
+            triger = !triger_base;
+        }
+        else
+        {
+            triger = triger_base;
+        }
     }
 }
 
@@ -146,18 +153,7 @@
     for(int i=0; i<2; i++)    
     {
         led1 = !led1;
-        b1 = !b1;
-        b2 = !b2;
-        b3 = !b3;
-        b4 = !b4;
-        /*
-        b5 = !b5;
-        b6 = !b6;
-        b7 = !b7;
-        b8 = !b5;
-        b9 = !b6;
-        b0 = !b7;
-        */
+        triger = !triger;
         wait(1);
     }
 }
@@ -171,65 +167,3 @@
     }
 }
 
-int flip(char value)
-{
-    int ret = 0;
-    
-    
-    switch(value)
-    {
-        // open door
-        case b1_id  :
-        case bA1_id :       led1 = !led1;
-                            b1 = 1;
-                            break;
-        // close door
-        case b2_id  :
-        case bA2_id :       led1 = !led1;
-                            b1 = 0;
-                            break;
-        // timed open 10 seconds
-        case b3_id  :
-        case bA3_id :       led1 = !led1;
-                            b1 = 1;
-                            wait(10);
-                            b1 = 0;
-                            break;
-        // light 1 on
-        case b4_id  :
-        case bA4_id :       led1 = !led1;
-                            b2 = 0;
-                            break;
-        // light 1 off
-        case b5_id  :
-        case bA5_id :       led1 = !led1;
-                            b2 = 1;
-                            break;
-        // light 2 on
-        case b6_id  :
-        case bA6_id :       led1 = !led1;
-                            b3 = 0;
-                            break;
-        // light 2 off
-        case b7_id  :
-        case bA7_id :       led1 = !led1;
-                            b3 = 1;
-                            break;
-        // light 3 on
-        case b8_id  :
-        case bA8_id :       led1 = !led1;
-                            b4 = 0;
-                            break;
-        // light 3 off
-        case b9_id  :
-        case bA9_id :       led1 = !led1;
-                            b4 = 1;
-                            break;
-                            
-        default :           blinky();
-                            ret = 1;
-                            break;
-    }
-
-    return ret;
-}
\ No newline at end of file