(in progress)

Dependencies:   LM75B EALib mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main_proj3.cpp Source File

main_proj3.cpp

00001 #include "LM75B.h" //Temperature header file
00002 #include "MMA7455.h" // Accelerometer header file
00003 #include "mbed.h"
00004 #include <cmath>
00005 
00006 Serial myUart (USBTX, USBRX);
00007 LM75B tempsensor(P0_27, P0_28, LM75B::ADDRESS_1);
00008 MMA7455 sensor(P0_27, P0_28);
00009 
00010 int main() // +/- 60 on X or Y = angle over 90 degrees
00011 {
00012     int temp_reading;
00013     int x, y, z;
00014     myUart.baud(19200); // setting the baud rate
00015     while(!sensor.setMode(MMA7455::ModeMeasurement));
00016     while(!sensor.calibrate());
00017      
00018     while(1) 
00019     {
00020         temp_reading = (int)tempsensor.temp();
00021         temp_reading *= 1.8;
00022         temp_reading += 32;
00023         myUart.printf("Current board temperature (Fahrenheit): %d.1\r", temp_reading);
00024         
00025         sensor.read(x,y,z);
00026         if (abs(x) > 60 || abs(y) > 60 || abs(z) > 40) //val +/- 60 = 90 degrees in all directions
00027             myUart.putc(0x07);
00028         
00029         wait(0.5); //Wait in seconds
00030     }     
00031 }