Jake Billingham
/
mbed_Y2PROJECT_FIRST
First draft of C file for Y2 project
Revision 0:8aebf9db3262, committed 2017-10-14
- Comitter:
- jbillingham
- Date:
- Sat Oct 14 11:51:51 2017 +0000
- Commit message:
- asdfghjkl;'#
Changed in this revision
diff -r 000000000000 -r 8aebf9db3262 ADXL362.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ADXL362.lib Sat Oct 14 11:51:51 2017 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/rmcwilliam101/code/ADXL362/#d9853774f233
diff -r 000000000000 -r 8aebf9db3262 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Sat Oct 14 11:51:51 2017 +0000 @@ -0,0 +1,65 @@ +//Add required libraries +#include "mbed.h" +#include "stdio.h" +#include "math.h" +#include "ADXL362.h" + +//Set up serial communication +Serial pc(USBTX, USBRX); +//Set up accelerometer +ADXL362 adxl362(p11, p12, p13, p10); + +//Initialise parameters +int N = 50; //Number of samples +float T = 0.1; //Sample period + +//Main function +int main() +{ + //Initialise variable used to exit/enter menu + int exitFlag = 0; + //Initialise variable to switch between menu options + int choice; + + //Initialise accelerometer + adxl362.init_spi(); + adxl362.init_adxl362(); + wait(0.1); + + //Initialise variables to hold accelerometer data + int8_t xdata, ydata, zdata; + + //Enter menu (not visible to user) + while(exitFlag == 0) //Will repeat this loop until exitflag set to 1 by user (to end program) + { + //Scans serial connection for command from MATLAB + pc.scanf("%i", &choice); + switch(choice) + { + //Switches here if int value 1 is recieved + case(1): + { + //For loop runs data collection N times to ensure correct number of samples + for(int i=0; i<N; i++) + { + //Gets accelerometer data + adxl362.ACC_GetXYZ8(&xdata,&ydata,&zdata); + //Sends accelerometer data to MATLAB via serial connection + pc.printf("%+04d\n", xdata); + pc.printf("%+04d\n", ydata); + pc.printf("%+04d\n", zdata); + //Waits time T to ensure sample rate + wait(T); + } + } + //Switches here if something other than menu options recieved from MATLAB + default: + { + //Sends error message to MATLAB (will then be relayed to user) + pc.printf("ERROR"); + } + } + } +} + + \ No newline at end of file
diff -r 000000000000 -r 8aebf9db3262 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Sat Oct 14 11:51:51 2017 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/b484a57bc302 \ No newline at end of file