(in progress)
Dependencies: LM75B EALib mbed
main_proj3.cpp@2:85472a77be8b, 2015-10-14 (annotated)
- Committer:
- lhinh3431
- Date:
- Wed Oct 14 23:34:59 2015 +0000
- Revision:
- 2:85472a77be8b
- Parent:
- 1:f5ad0c1f9d0f
Finalized project 3
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kinetik | 1:f5ad0c1f9d0f | 1 | #include "LM75B.h" //Temperature header file |
kinetik | 1:f5ad0c1f9d0f | 2 | #include "MMA7455.h" // Accelerometer header file |
kinetik | 1:f5ad0c1f9d0f | 3 | #include "mbed.h" |
lhinh3431 | 2:85472a77be8b | 4 | #include <cmath> |
kinetik | 0:53a593dea14e | 5 | |
kinetik | 0:53a593dea14e | 6 | Serial myUart (USBTX, USBRX); |
kinetik | 1:f5ad0c1f9d0f | 7 | LM75B tempsensor(P0_27, P0_28, LM75B::ADDRESS_1); |
kinetik | 0:53a593dea14e | 8 | MMA7455 sensor(P0_27, P0_28); |
kinetik | 0:53a593dea14e | 9 | |
lhinh3431 | 2:85472a77be8b | 10 | int main() // +/- 60 on X or Y = angle over 90 degrees |
kinetik | 0:53a593dea14e | 11 | { |
lhinh3431 | 2:85472a77be8b | 12 | int temp_reading; |
lhinh3431 | 2:85472a77be8b | 13 | int x, y, z; |
kinetik | 0:53a593dea14e | 14 | myUart.baud(19200); // setting the baud rate |
lhinh3431 | 2:85472a77be8b | 15 | while(!sensor.setMode(MMA7455::ModeMeasurement)); |
lhinh3431 | 2:85472a77be8b | 16 | while(!sensor.calibrate()); |
kinetik | 1:f5ad0c1f9d0f | 17 | |
lhinh3431 | 2:85472a77be8b | 18 | while(1) |
lhinh3431 | 2:85472a77be8b | 19 | { |
lhinh3431 | 2:85472a77be8b | 20 | temp_reading = (int)tempsensor.temp(); |
lhinh3431 | 2:85472a77be8b | 21 | temp_reading *= 1.8; |
lhinh3431 | 2:85472a77be8b | 22 | temp_reading += 32; |
lhinh3431 | 2:85472a77be8b | 23 | myUart.printf("Current board temperature (Fahrenheit): %d.1\r", temp_reading); |
kinetik | 0:53a593dea14e | 24 | |
lhinh3431 | 2:85472a77be8b | 25 | sensor.read(x,y,z); |
lhinh3431 | 2:85472a77be8b | 26 | if (abs(x) > 60 || abs(y) > 60 || abs(z) > 40) //val +/- 60 = 90 degrees in all directions |
lhinh3431 | 2:85472a77be8b | 27 | myUart.putc(0x07); |
kinetik | 0:53a593dea14e | 28 | |
lhinh3431 | 2:85472a77be8b | 29 | wait(0.5); //Wait in seconds |
kinetik | 0:53a593dea14e | 30 | } |
lhinh3431 | 2:85472a77be8b | 31 | } |