Device 1 for Iot group project.

Dependencies:   C12832 FXOS8700Q LM75B MMA7660 mbed

Files at this revision

API Documentation at this revision

Comitter:
co657_mh560
Date:
Mon Jan 25 20:52:49 2016 +0000
Parent:
0:41a47fd5d1cb
Commit message:

Changed in this revision

FXOS8700Q.lib Show annotated file Show diff for this revision Revisions of this file
device1.cpp Show annotated file Show diff for this revision Revisions of this file
device2.cpp Show diff for this revision Revisions of this file
main.cpp Show diff for this revision Revisions of this file
diff -r 41a47fd5d1cb -r 9a7edbd937fd FXOS8700Q.lib
--- a/FXOS8700Q.lib	Sun Jan 24 14:02:54 2016 +0000
+++ b/FXOS8700Q.lib	Mon Jan 25 20:52:49 2016 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/JimCarver/code/FXOS8700Q/#5553a64d0762
+http://developer.mbed.org/teams/Freescale/code/FXOS8700Q/#aee7dea904e2
diff -r 41a47fd5d1cb -r 9a7edbd937fd device1.cpp
--- a/device1.cpp	Sun Jan 24 14:02:54 2016 +0000
+++ b/device1.cpp	Mon Jan 25 20:52:49 2016 +0000
@@ -1,98 +1,106 @@
 #include "mbed.h"
 #include "LM75B.h"     /* On sheild Temp sensor */
-#include "MMA7660.h"   /* On sheild Accelerometer */
 #include "C12832.h"    /* On sheild LCD */
 #include "FXOS8700Q.h"
 
-//I2C i2c (PTE25, PTE24);
-DigitalOut gpo (D0);
-DigitalOut led (LED_RED);
 PwmOut speaker (D6);
 Serial host    (USBTX, USBRX);
 LM75B temp     (D14, D15);
 C12832 lcd     (D11, D13, D12, D7, D10);
 Serial xbee    (D1, D0);
-
-FXOS8700Q_mag mag( PTE25, PTE24, FXOS8700CQ_SLAVE_ADDR1);
+DigitalOut green_led_shield (PTA2);     /**/
+DigitalOut red_led_shield (PTC4);       /* Shield LEDs */
+DigitalOut blue_led_shield (PTA0);      /**/
+I2C i2c(PTE25, PTE24);
+FXOS8700QMagnetometer mag(i2c, FXOS8700CQ_SLAVE_ADDR1);
 
-char input;
+//Global variables
+char input = '0';
 char alert = 'A'; // degree
-char warn  = 'W'; // temp
-char dang  = 'D'; // degree + temp alert 
-
+char warn  = 'W'; // temp 
+char history = '0';
 float x,y,z,tp, degree;
 
-/* On board magnometer */
-void onbmag (void)
+/* Makes the LED red */
+void makeLEDRed (void)
 {
-        MotionSensorDataCounts mag_raw;
-        mag.getAxis(mag_raw);               /* reads raw Magnetometer data */
-        float magx = mag_raw.x;
-        float magy = mag_raw.y;
-        float degree = abs(atan2(magx,magy)*180*7/22);
-    
+    green_led_shield = 0;
+    red_led_shield = 255;
+    blue_led_shield = 0;
+}
+
+/* Makes the LED green */
+void makeLEDGreen (void)
+{
+    green_led_shield = 255;
+    red_led_shield = 0;
+    blue_led_shield = 0;
 }
 
 int main()
 {
     host.baud(38400);
-    void onbmag();
+    makeLEDGreen();
     float anti = abs(degree); 
+    mag.enable();
     for(;;)
     {
-        
-  
-    
-        void onbmag();
-        tp = temp.read ();
+        //Gather the data from the magnetometer 
+        motion_data_counts_t mag_raw;
+        mag.getAxis(mag_raw);               
+        float magx; 
+        float magy;   
+        float degree = abs(atan2(magx,magy)*180*7/22);        
+        mag.getX(magx);
+        mag.getY(magy);
+        //Print the data onto the LCD 
         lcd.cls();
-        lcd.locate(0,1);
-        lcd.printf ("Temp: %.3f F", tp);
-        lcd.locate(10,1);
-        lcd.printf ("Mag: %.0f", degree); 
-        xbee.putc((float)(degree));
-        xbee.putc((float)(tp));
+        lcd.locate(1,1);
+        lcd.printf("Magnetometer Degree: %.3f", degree);
+        lcd.locate(1,11);
+        tp = temp.read();
+        lcd.printf("Temperature: %.3f C", tp);
+        host.printf("%2.1f%3.0f%c\r\n", tp,degree,input);
+        xbee.printf("%2.1f%3.0f%c", tp,degree,input);
+        wait_ms(500);
+        input = '0';
+    
         
         // If the door moves, Send alert 
-        if (abs(anti-degree) > 45 )
+        if (abs(anti-degree) > 160 )
         {
-            // sends the char 
-            xbee.putc((char)(alert));
+           makeLEDRed(); 
+           speaker.period(1/500);
+           speaker=0.5;
+         
+           input = alert;
             
         }
+        
+        // If the temp goes too high or too low, send warning
         if (tp < 0 || tp > 45)
         {  
-            xbee.putc((char)(warn));
+            makeLEDRed();
+            speaker.period(1/500);
+            speaker=0.5;
+            input = warn;
         }
+        
         //Receiving char response 
         if(xbee.readable())
         {
-        input = xbee.getc();
-        switch(input)
-        {
-            case 'y':
-            speaker.period(1.0/500.0);
-            speaker=0.5;
-            break;
-            
-            case 'Y':
-            speaker.period(1.0/500.0);
-            speaker=0.5;
-            break;
+            input = xbee.getc();
+            switch(input)
+            {
+                case 'y':
+                makeLEDGreen();
+                speaker=0;
+                break;
             
-            case 'n':
-            speaker.period(5.0/500.0);
-            speaker=2.5;
-            break;
-            
-            case 'N':
-            speaker.period(5.0/500.0);
-            speaker=2.5;
-            break;
+                case 's':
+                speaker=0;
+                break;
+            }
         }
-      
-  
     }
-    
-    }
-    }
+}
\ No newline at end of file
diff -r 41a47fd5d1cb -r 9a7edbd937fd device2.cpp
--- a/device2.cpp	Sun Jan 24 14:02:54 2016 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,122 +0,0 @@
-#include "mbed.h"
-#include "LM75B.h"     /* On sheild Temp sensor */
-#include "MMA7660.h"   /* On sheild Accelerometer */
-#include "C12832.h"    /* On sheild LCD */
-
-DigitalOut gpo (D0);
-DigitalOut led (LED_RED);
-PwmOut speaker (D6);
-Serial host    (USBTX, USBRX);
-LM75B temp     (D14, D15);
-C12832 lcd     (D11, D13, D12, D7, D10);
-Serial xbee    (D1, D0);
-
-char input;
-char yes   = 'Y';
-char no    = 'N';
-char stop  = 'S';
-char pcin;
-
-int main()
-{
-    host.baud(38400);
-    for(;;)
-    {
-        if(xbee.readable())
-        input = xbee.getc();
-        // If the Xbee receives data from device 1 either an alert or warning 
-        switch(input)
-        {
-            case 'A':
-            speaker.period(1.0/500.0);
-            speaker=0.5;
-            host.printf("ALERT, Motion Detected \r\n");
-            pcin = host.getc();
-            while(!host.readable())
-            {
-                switch(pcin)
-                {
-                    // use both cases as to add ease for the user 
-                    case'Y':
-                    speaker.period(1.0/500.0);
-                    speaker=0.5;
-                    xbee.putc((char)(yes));
-                    break;
-                    
-                    case'y':
-                    speaker.period(1.0/500.0);
-                    speaker=0.5;
-                    xbee.putc((char)(yes));
-                    break;
-                    
-                    case'N':
-                    speaker.period(5.0/500.0);
-                    speaker=2.5;
-                    xbee.putc((char)(no));
-                    break;
-                    
-                    case'n':
-                    speaker.period(5.0/500.0);
-                    speaker=2.5;
-                    xbee.putc((char)(no));
-                    break;
-                    
-                }
-                      char p = host.getc();
-                      
-            }
-                
-            break;
-            
-            case 'W':
-            speaker.period(1.0/500.0);
-            speaker=0.5;
-            host.printf("WARNING, Temperature at critical levels \r\n");
-            pcin;
-            while(!host.readable())
-            {
-                switch(pcin)
-                {
-                   
-                    
-                    case's':
-                    speaker.period(1.0/500.0);
-                    speaker=0.5;
-                    xbee.putc((char)(stop));
-                    break;
-                    
-                    case'S':
-                    speaker.period(1.0/500.0);
-                    speaker=0.5;
-                    xbee.putc((char)(stop));
-                    break;
-                      
-                }
-                
-                   char p = host.getc();   
-            }
-            break;
-            
-        }
-        
-        // needs working on
-        
-        if (sw2_trig or whatever) 
-        {
-            xbee.putc((char)(yes));    
-            
-        }
-        if (time exceeds 300000000)
-        {
-            xbee.putc((char)(no));    
-            
-        }
-            
-            
-            
-            
-            
-        }
-        
-    }
-}
\ No newline at end of file
diff -r 41a47fd5d1cb -r 9a7edbd937fd main.cpp
--- a/main.cpp	Sun Jan 24 14:02:54 2016 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,25 +0,0 @@
-#include "mbed.h"
-#include "LM75B.h"     /* On sheild Temp sensor */
-#include "MMA7660.h"   /* On sheild Accelerometer */
-#include "C12832.h"    /* On sheild LCD */
-
-DigitalOut gpo (D0);
-DigitalOut led (LED_RED);
-PwmOut speaker (D6);
-Serial host    (USBTX, USBRX);
-LM75B temp     (D14, D15);
-C12832 lcd     (D11, D13, D12, D7, D10);
-Serial xbee    (D1, D0);
-
-char input;
-
-int main()
-{
-    for(;;)
-    {
-        if(xbee.readable())
-        input = xbee.getc();
-        
-        
-    }
-}
\ No newline at end of file