Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: C12832 FXOS8700Q LM75B MMA7660 mbed
device1.cpp
00001 #include "mbed.h" 00002 #include "LM75B.h" /* On sheild Temp sensor */ 00003 #include "C12832.h" /* On sheild LCD */ 00004 #include "FXOS8700Q.h" 00005 00006 PwmOut speaker (D6); 00007 Serial host (USBTX, USBRX); 00008 LM75B temp (D14, D15); 00009 C12832 lcd (D11, D13, D12, D7, D10); 00010 Serial xbee (D1, D0); 00011 DigitalOut green_led_shield (PTA2); /**/ 00012 DigitalOut red_led_shield (PTC4); /* Shield LEDs */ 00013 DigitalOut blue_led_shield (PTA0); /**/ 00014 I2C i2c(PTE25, PTE24); 00015 FXOS8700QMagnetometer mag(i2c, FXOS8700CQ_SLAVE_ADDR1); 00016 00017 //Global variables 00018 char input = '0'; 00019 char alert = 'A'; // degree 00020 char warn = 'W'; // temp 00021 char history = '0'; 00022 float x,y,z,tp, degree; 00023 00024 /* Makes the LED red */ 00025 void makeLEDRed (void) 00026 { 00027 green_led_shield = 0; 00028 red_led_shield = 255; 00029 blue_led_shield = 0; 00030 } 00031 00032 /* Makes the LED green */ 00033 void makeLEDGreen (void) 00034 { 00035 green_led_shield = 255; 00036 red_led_shield = 0; 00037 blue_led_shield = 0; 00038 } 00039 00040 int main() 00041 { 00042 host.baud(38400); 00043 makeLEDGreen(); 00044 float anti = abs(degree); 00045 mag.enable(); 00046 for(;;) 00047 { 00048 //Gather the data from the magnetometer 00049 motion_data_counts_t mag_raw; 00050 mag.getAxis(mag_raw); 00051 float magx; 00052 float magy; 00053 float degree = abs(atan2(magx,magy)*180*7/22); 00054 mag.getX(magx); 00055 mag.getY(magy); 00056 //Print the data onto the LCD 00057 lcd.cls(); 00058 lcd.locate(1,1); 00059 lcd.printf("Magnetometer Degree: %.3f", degree); 00060 lcd.locate(1,11); 00061 tp = temp.read(); 00062 lcd.printf("Temperature: %.3f C", tp); 00063 host.printf("%2.1f%3.0f%c\r\n", tp,degree,input); 00064 xbee.printf("%2.1f%3.0f%c", tp,degree,input); 00065 wait_ms(500); 00066 input = '0'; 00067 00068 00069 // If the door moves, Send alert 00070 if (abs(anti-degree) > 160 ) 00071 { 00072 makeLEDRed(); 00073 speaker.period(1/500); 00074 speaker=0.5; 00075 00076 input = alert; 00077 00078 } 00079 00080 // If the temp goes too high or too low, send warning 00081 if (tp < 0 || tp > 45) 00082 { 00083 makeLEDRed(); 00084 speaker.period(1/500); 00085 speaker=0.5; 00086 input = warn; 00087 } 00088 00089 //Receiving char response 00090 if(xbee.readable()) 00091 { 00092 input = xbee.getc(); 00093 switch(input) 00094 { 00095 case 'y': 00096 makeLEDGreen(); 00097 speaker=0; 00098 break; 00099 00100 case 's': 00101 speaker=0; 00102 break; 00103 } 00104 } 00105 } 00106 }
Generated on Tue Aug 2 2022 08:44:15 by
 1.7.2
 1.7.2