Final

Dependencies:   TextLCD mbed

Files at this revision

API Documentation at this revision

Comitter:
pstephens18
Date:
Wed Jan 20 02:15:26 2016 +0000
Commit message:
final

Changed in this revision

Compass.cpp Show annotated file Show diff for this revision Revisions of this file
Compass.h Show annotated file Show diff for this revision Revisions of this file
Tap.cpp Show annotated file Show diff for this revision Revisions of this file
Tap.h Show annotated file Show diff for this revision Revisions of this file
Temperature.cpp Show annotated file Show diff for this revision Revisions of this file
Temperature.h Show annotated file Show diff for this revision Revisions of this file
TextLCD.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 5fd3f73db34f Compass.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Compass.cpp	Wed Jan 20 02:15:26 2016 +0000
@@ -0,0 +1,44 @@
+#include "Compass.h"
+extern I2C acc;
+char rawBytes[6];
+short data[6];
+short magComponents[3];
+double heading;
+const int addr1 = (0x1E << 1);
+char config[2];
+char init[2];
+double Compass() 
+{
+    config[0]= 0x02;
+    config[1] = 0x00;
+    acc.write(addr1, config,2);
+    init[0]=0x03;
+    while(1)
+    {
+       acc.write(addr1,init,1);
+       acc.read(addr1,rawBytes,6);
+        
+        
+        for (int i = 0; i<6; i++) 
+        {
+            data[i] = rawBytes[i];
+        }
+        
+        magComponents[0] = data[0]<<8 | data[1];
+        magComponents[1] = data[4]<<8 | data[5];
+        magComponents[2] = data[2]<<8 | data[3];
+        
+        heading = atan2((double)magComponents[1],(double)magComponents[0]); // Angle in Radians
+        heading = (heading*180)/3.14159;   // Convert to Degrees
+        heading = heading + 14.85;  // Find True North
+        if(heading > 180)
+        {
+            heading -= 360;    
+        }
+       
+        return heading;
+    }
+}
+
+
+
diff -r 000000000000 -r 5fd3f73db34f Compass.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Compass.h	Wed Jan 20 02:15:26 2016 +0000
@@ -0,0 +1,8 @@
+#ifndef COMPASS_H
+#define COMPASS_H
+#include "mbed.h"
+
+
+double Compass();
+
+#endif
\ No newline at end of file
diff -r 000000000000 -r 5fd3f73db34f Tap.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Tap.cpp	Wed Jan 20 02:15:26 2016 +0000
@@ -0,0 +1,52 @@
+// CS needs to be connected to High in order to do I2C
+
+#include "Tap.h"
+extern I2C acc;
+DigitalIn int2(p17);
+
+char acc_config[2];
+const int addr=(0x53<<1);
+char data1[1];
+char ack;
+Timer b;
+
+
+void Tap_init() 
+    {
+    wait(0.1);  
+    acc_config[0]=0x31; acc_config[1]=0x0B;         //data format
+    ack = acc.write(addr,acc_config, 2);
+    wait(0.1);
+      
+    acc_config[0]=0x2D; acc_config[1]=0x08;         //power control->measure mode
+    acc.write(addr,acc_config, 2);   
+    wait(0.1);
+    
+    acc_config[0]=0x1D; acc_config[1]=0x50;         //Tap Threshold ->5g 
+    acc.write(addr,acc_config, 2); 
+    wait(0.1);
+    
+    acc_config[0]=0x21; acc_config[1]=0x10;         //Tap duration -> 0.01
+    acc.write(addr,acc_config, 2);    
+    wait(0.1);
+    
+    acc_config[0]=0x2A; acc_config[1]=0x07;         //Axis -> x&y&z
+    acc.write(addr,acc_config, 2);
+    wait(0.1);
+    
+    acc_config[0]=0x2E; acc_config[1]=0x40;         //enable interupt -> single and double tap
+    acc.write(addr,acc_config, 2);
+    wait(0.1);
+    
+    acc_config[0]=0x2F; acc_config[1]=0x40;         //map interupt ->int2
+    acc.write(addr,acc_config, 2);
+    wait(0.1);
+    }
+    
+void Tap()
+{      
+                    acc_config[0]=0x30;
+                    acc.write(addr,acc_config,1);            
+                    acc.read(addr,data1,1);  // Get interupt information                 
+}
+
diff -r 000000000000 -r 5fd3f73db34f Tap.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Tap.h	Wed Jan 20 02:15:26 2016 +0000
@@ -0,0 +1,8 @@
+#ifndef TAP_H
+#define TAP_H
+#include "mbed.h"
+
+void Tap_init();
+void Tap();
+
+#endif
\ No newline at end of file
diff -r 000000000000 -r 5fd3f73db34f Temperature.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Temperature.cpp	Wed Jan 20 02:15:26 2016 +0000
@@ -0,0 +1,25 @@
+#include "Temperature.h"
+extern I2C acc;
+
+const int addr = 0x90;
+char config_t[3];
+char temp_read[2];
+float temp;
+
+float Temperature() 
+{
+    config_t[0] = 0x01;         // Setting Up Temperature
+    config_t[1] = 0x60;
+    config_t[2] = 0xA0;
+    acc.write(addr,config_t,3);
+    config_t[0] =0x00;
+    acc.write(addr,config_t,1);
+    
+    
+    wait(.5);
+    acc.read(addr, temp_read,2);         // Reading Temperature
+    temp= 0.0625*(((temp_read[0] << 8) + temp_read[1]) >> 4);           // Converting Temperature to Celcius
+      
+
+    return temp; 
+}
\ No newline at end of file
diff -r 000000000000 -r 5fd3f73db34f Temperature.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Temperature.h	Wed Jan 20 02:15:26 2016 +0000
@@ -0,0 +1,8 @@
+#ifndef TEMPERATURE_H
+#define TEMPERATURE_H
+#include "mbed.h"
+
+
+float Temperature();
+
+#endif
\ No newline at end of file
diff -r 000000000000 -r 5fd3f73db34f TextLCD.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TextLCD.lib	Wed Jan 20 02:15:26 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/simon/code/TextLCD/#308d188a2d3a
diff -r 000000000000 -r 5fd3f73db34f main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Jan 20 02:15:26 2016 +0000
@@ -0,0 +1,79 @@
+#include "Compass.h"
+#include "Temperature.h"
+#include "mbed.h"
+#include "Tap.h"
+#include "TextLCD.h"
+
+TextLCD lcd(p19,p20,p21,p22,p23,p24);
+I2C acc(p9,p10);
+InterruptIn to(p5);
+Serial pc(USBTX,USBRX);
+
+double direction;
+float temp2;
+float tap;
+float test;
+void Temperature(float t);
+void Direction(double d);
+void toggle(void);
+void printReading(void);
+Ticker t;
+bool displayTemperature;
+DigitalOut led(LED1);
+
+int main() 
+{
+    displayTemperature = 1;
+    Tap_init();
+    Tap();
+    t.attach(&printReading,3);
+    to.rise(&toggle);
+    pc.printf("Beginning \n\r");   
+    while(1) {Tap();}
+    
+}
+
+
+   /*
+        
+        direction = Compass();
+        temp2 = Temperature();
+        test = Tap();
+        
+        if(test ==1)
+        {
+           Direction(direction);
+           Temperature(temp2);
+        }
+        test =0;
+        // pc.printf( "%1.2f = Taps, %1.2f = Temp, %1.2f = Direction  \n\r" , tap, temp2, direction); 
+        */
+        
+void printReading() 
+{
+        if (displayTemperature){
+            Temperature(Temperature());}
+        else{
+            Direction(Compass());}
+}
+        
+void Direction(double d)
+{
+        lcd.cls();
+        pc.printf( "%1.2f = Direction  \n\r" , d); 
+        lcd.printf("%1.2f = Direction" , d);
+}
+
+void Temperature(float t)
+{
+        lcd.cls();
+        pc.printf( "%1.2f = Temperature  \n\r" , t);
+        lcd.printf( "%1.2f = Temperature" , t);
+}
+
+void toggle(void)
+{
+        displayTemperature = !displayTemperature;
+        Tap();
+        led=!led;
+}
diff -r 000000000000 -r 5fd3f73db34f mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Wed Jan 20 02:15:26 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/6f327212ef96
\ No newline at end of file