This is the development sandbox for the DRV425EVM and its magnetic sensing.

Dependencies:   mbed

/media/uploads/Krabby127/ohmboyzvectorized.png

Repository for the 2015 OhmBoyZ Capstone group.

Committer:
Krabby127
Date:
Tue Nov 17 17:26:59 2015 +0000
Revision:
1:d901038c4bd2
Parent:
0:cbee968c2ec3
Child:
2:a17facee23c1
Updated comments for readability

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Krabby127 0:cbee968c2ec3 1 #include "mbed.h"
Krabby127 0:cbee968c2ec3 2 #include <math.h>
Krabby127 0:cbee968c2ec3 3
Krabby127 0:cbee968c2ec3 4 AnalogIn analog_value(A0);
Krabby127 0:cbee968c2ec3 5
Krabby127 0:cbee968c2ec3 6 DigitalOut led(LED1);
Krabby127 0:cbee968c2ec3 7
Krabby127 0:cbee968c2ec3 8 int main() {
Krabby127 0:cbee968c2ec3 9 float meas;
Krabby127 0:cbee968c2ec3 10 float b;
Krabby127 0:cbee968c2ec3 11 float offset;
Krabby127 0:cbee968c2ec3 12 printf("\nAnalogIn example\n");
Krabby127 0:cbee968c2ec3 13 while(1) {
Krabby127 0:cbee968c2ec3 14 meas = analog_value.read(); // Converts and read the analog input value (value from 0.0 to 1.0)
Krabby127 0:cbee968c2ec3 15 meas = meas * 3300; // Change the value to be in the 0 to 3300 range (currently to mV)
Krabby127 1:d901038c4bd2 16 printf("meas = %fmV\n\r",meas); // Print out raw measurement in terms of mV
Krabby127 1:d901038c4bd2 17 b=meas/(4.0*12.2*100.0); // Based on equation 1
Krabby127 1:d901038c4bd2 18 printf("b = %f Gauss\n\r",b); // Print out b field measure in Gauss
Krabby127 0:cbee968c2ec3 19 printf("B = %fuT\n\r", b*100.0); // Output B field in micro-Tesla
Krabby127 1:d901038c4bd2 20 if (meas > 2000) { // If the value is greater than 2V then switch the LED on
Krabby127 1:d901038c4bd2 21 // greater than 410 microGauss [40 mT]
Krabby127 0:cbee968c2ec3 22 led = 1;
Krabby127 0:cbee968c2ec3 23 }
Krabby127 0:cbee968c2ec3 24 else {
Krabby127 0:cbee968c2ec3 25 led = 0;
Krabby127 0:cbee968c2ec3 26 }
Krabby127 1:d901038c4bd2 27 wait(1.0); // wait 1 second
Krabby127 0:cbee968c2ec3 28 }
Krabby127 0:cbee968c2ec3 29 }