This is the development sandbox for the DRV425EVM and its magnetic sensing.
Dependencies: mbed
Repository for the 2015 OhmBoyZ Capstone group.
main.cpp@0:cbee968c2ec3, 2015-11-17 (annotated)
- Committer:
- Krabby127
- Date:
- Tue Nov 17 17:19:01 2015 +0000
- Revision:
- 0:cbee968c2ec3
- Child:
- 1:d901038c4bd2
Created copy to use
Who changed what in which revision?
User | Revision | Line number | New 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 | 0:cbee968c2ec3 | 16 | b=meas/(4.0*12.2*100.0); // Based 9h |
Krabby127 | 0:cbee968c2ec3 | 17 | printf("meas = %fmV\n\r",meas); |
Krabby127 | 0:cbee968c2ec3 | 18 | printf("b = %f Gauss\n\r",b); |
Krabby127 | 0:cbee968c2ec3 | 19 | printf("B = %fuT\n\r", b*100.0); // Output B field in micro-Tesla |
Krabby127 | 0:cbee968c2ec3 | 20 | if (meas > 2000) { // If the value is greater than 2V then switch the LED on (greater than |
Krabby127 | 0:cbee968c2ec3 | 21 | led = 1; |
Krabby127 | 0:cbee968c2ec3 | 22 | } |
Krabby127 | 0:cbee968c2ec3 | 23 | else { |
Krabby127 | 0:cbee968c2ec3 | 24 | led = 0; |
Krabby127 | 0:cbee968c2ec3 | 25 | } |
Krabby127 | 0:cbee968c2ec3 | 26 | wait(1.0); // 1 s |
Krabby127 | 0:cbee968c2ec3 | 27 | } |
Krabby127 | 0:cbee968c2ec3 | 28 | } |