lab5

Dependencies:   ADXL362

Files at this revision

API Documentation at this revision

Comitter:
kfricker
Date:
Mon Feb 26 01:39:55 2018 +0000
Child:
1:839c14f3143c
Commit message:
lab5;

Changed in this revision

.gitignore Show annotated file Show diff for this revision Revisions of this file
ADXL362.lib Show annotated file Show diff for this revision Revisions of this file
README.md 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-os.lib Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/.gitignore	Mon Feb 26 01:39:55 2018 +0000
@@ -0,0 +1,4 @@
+.build
+.mbed
+projectfiles
+*.py*
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ADXL362.lib	Mon Feb 26 01:39:55 2018 +0000
@@ -0,0 +1,1 @@
+http://os.mbed.com/teams/AnalogDevices/code/ADXL362/#ae171c032dc0
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/README.md	Mon Feb 26 01:39:55 2018 +0000
@@ -0,0 +1,57 @@
+# Getting started with Blinky on mbed OS
+
+This guide reviews the steps required to get Blinky working on an mbed OS platform.
+
+Please install [mbed CLI](https://github.com/ARMmbed/mbed-cli#installing-mbed-cli).
+
+## Import the example application
+
+From the command-line, import the example:
+
+```
+mbed import mbed-os-example-blinky
+cd mbed-os-example-blinky
+```
+
+### Now compile
+
+Invoke `mbed compile`, and specify the name of your platform and your favorite toolchain (`GCC_ARM`, `ARM`, `IAR`). For example, for the ARM Compiler 5:
+
+```
+mbed compile -m K64F -t ARM
+```
+
+Your PC may take a few minutes to compile your code. At the end, you see the following result:
+
+```
+[snip]
++----------------------------+-------+-------+------+
+| Module                     | .text | .data | .bss |
++----------------------------+-------+-------+------+
+| Misc                       | 13939 |    24 | 1372 |
+| core/hal                   | 16993 |    96 |  296 |
+| core/rtos                  |  7384 |    92 | 4204 |
+| features/FEATURE_IPV4      |    80 |     0 |  176 |
+| frameworks/greentea-client |  1830 |    60 |   44 |
+| frameworks/utest           |  2392 |   512 |  292 |
+| Subtotals                  | 42618 |   784 | 6384 |
++----------------------------+-------+-------+------+
+Allocated Heap: unknown
+Allocated Stack: unknown
+Total Static RAM memory (data + bss): 7168 bytes
+Total RAM memory (data + bss + heap + stack): 7168 bytes
+Total Flash memory (text + data + misc): 43402 bytes
+Image: .\.build\K64F\ARM\mbed-os-example-blinky.bin
+```
+
+### Program your board
+
+1. Connect your mbed device to the computer over USB.
+1. Copy the binary file to the mbed device.
+1. Press the reset button to start the program.
+
+The LED on your platform turns on and off.
+
+## Troubleshooting
+
+If you have problems, you can review the [documentation](https://os.mbed.com/docs/latest/tutorials/debugging.html) for suggestions on what could be wrong and how to fix it.
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon Feb 26 01:39:55 2018 +0000
@@ -0,0 +1,71 @@
+#include "mbed.h"
+#include "ADXL362.h"
+DigitalOut led1(LED1);
+ 
+// Interface pulled from ADXL362.cpp
+// ADXL362::ADXL362(PinName CS, PinName MOSI, PinName MISO, PinName SCK) :
+ADXL362 adxl362(PA_0,PA_7,PA_6,PA_1);
+
+int adxl362_reg_print(int start, int length){
+     for(int x = 0x00; x<=0x2E; x++){
+        if(start==x){
+            if(length>0){
+             if(ADXL362::DEVID_AD==0xAD){
+                uint16_t return_val = adxl362.read_reg(ADXL362::DEVID_AD);
+             }
+            }
+        }           
+     }
+     
+     //printf("%x\n","0x" , return_val);
+     return return_val;
+}
+
+int main() {
+    adxl362.reset();
+    wait_ms(600); // we need to wait at least 500ms after ADXL362 reset
+    adxl362.set_mode(ADXL362::MEASUREMENT);
+    int8_t x,y,z; 
+    
+    int8_t current [3] = {0,0,0};
+    int8_t accel [3] = {0,0,0};
+    int8_t currAdd;
+    int8_t diffAdd;
+    float threshold = 2;
+    float val;
+    int knock_counter = 0;
+    
+        while(1) {
+            x=adxl362.scanx_u8();
+            y=adxl362.scany_u8();
+            z=adxl362.scanz_u8();
+             current [0] = x; 
+             current [1] = y; 
+             current [2] = z; 
+             currAdd = abs(current[0] + current [1] + current [2]);
+            wait_ms(10);
+            x=adxl362.scanx_u8();
+            y=adxl362.scany_u8();
+            z=adxl362.scanz_u8();
+                accel[0] = x;
+                accel[1] = y;
+                accel[2] = z;
+                diffAdd = abs(accel[0] + accel [1] + accel [2]);
+            wait_ms(10);
+            val = abs(currAdd - diffAdd);
+            
+            if(val > threshold){
+             printf("A knock has been heard ma dude\r\n");
+             knock_counter ++;
+            printf("Knocks = %d\r\n" , knock_counter);
+             led1 = 1;
+             wait_ms(2000);
+             led1 = 0;
+             }
+          //  printf("x = %d y = %d z = %d\r\n",x,y,z);
+        wait_ms(100);
+    
+  
+        
+    }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-os.lib	Mon Feb 26 01:39:55 2018 +0000
@@ -0,0 +1,1 @@
+https://github.com/ARMmbed/mbed-os/#569159b784f70feaa32ce226aaca896fb83452f7