FacingSouthHouseFinder_WIZwiki-W7500

Dependencies:   HMC5883L mbed

description : http://www.instructables.com/id/Facing-South-House-Finder/

Committer:
justinkim
Date:
Wed Aug 26 06:21:32 2015 +0000
Revision:
0:e5950ca3f38f
facingsouthhousefinder first release

Who changed what in which revision?

UserRevisionLine numberNew contents of line
justinkim 0:e5950ca3f38f 1 /**
justinkim 0:e5950ca3f38f 2 ******************************************************************************
justinkim 0:e5950ca3f38f 3 * @project mbed project
justinkim 0:e5950ca3f38f 4 * @author Justin Kim
justinkim 0:e5950ca3f38f 5 * @version V1.0.0
justinkim 0:e5950ca3f38f 6 * @date 00-AUG-2015
justinkim 0:e5950ca3f38f 7 * @brief Main program body
justinkim 0:e5950ca3f38f 8 *******************************************************************************
justinkim 0:e5950ca3f38f 9 **/
justinkim 0:e5950ca3f38f 10 /* Includes ------------------------------------------------------------------*/
justinkim 0:e5950ca3f38f 11 #include "mbed.h"
justinkim 0:e5950ca3f38f 12 #include "HMC5883L.h"
justinkim 0:e5950ca3f38f 13
justinkim 0:e5950ca3f38f 14 /* Private typedef -----------------------------------------------------------*/
justinkim 0:e5950ca3f38f 15 /* Private define ------------------------------------------------------------*/
justinkim 0:e5950ca3f38f 16 /* Private variables ---------------------------------------------------------*/
justinkim 0:e5950ca3f38f 17 DigitalOut myled_R1(PC_1);
justinkim 0:e5950ca3f38f 18 DigitalOut myled_R2(PC_0);
justinkim 0:e5950ca3f38f 19 DigitalOut myled_R3(PA_2);
justinkim 0:e5950ca3f38f 20 DigitalOut myled_R4(PA_1);
justinkim 0:e5950ca3f38f 21 DigitalOut myled_G1(PA_0);
justinkim 0:e5950ca3f38f 22 DigitalOut myled_G2(PC_6);
justinkim 0:e5950ca3f38f 23 DigitalOut myled_G3(PC_7);
justinkim 0:e5950ca3f38f 24 DigitalOut myled_G4(PC_4);
justinkim 0:e5950ca3f38f 25 DigitalOut myled_Y1(PA_5);
justinkim 0:e5950ca3f38f 26 DigitalOut myled_Y2(PA_8);
justinkim 0:e5950ca3f38f 27 DigitalOut myled_Y3(PA_7);
justinkim 0:e5950ca3f38f 28 DigitalOut myled_Y4(PA_6);
justinkim 0:e5950ca3f38f 29
justinkim 0:e5950ca3f38f 30 Serial pc(USBTX,USBRX); // default baud rate: 9600
justinkim 0:e5950ca3f38f 31 HMC5883L hmc5883l;
justinkim 0:e5950ca3f38f 32
justinkim 0:e5950ca3f38f 33 double Heading;
justinkim 0:e5950ca3f38f 34 float DataBuf[3] ={0};
justinkim 0:e5950ca3f38f 35
justinkim 0:e5950ca3f38f 36 /* Private function prototypes -----------------------------------------------*/
justinkim 0:e5950ca3f38f 37 /* Private functions ---------------------------------------------------------*/
justinkim 0:e5950ca3f38f 38 /**
justinkim 0:e5950ca3f38f 39 * @brief Main Function
justinkim 0:e5950ca3f38f 40 * @param None
justinkim 0:e5950ca3f38f 41 * @retval None
justinkim 0:e5950ca3f38f 42 */
justinkim 0:e5950ca3f38f 43 int main(void)
justinkim 0:e5950ca3f38f 44 {
justinkim 0:e5950ca3f38f 45 hmc5883l.init();
justinkim 0:e5950ca3f38f 46
justinkim 0:e5950ca3f38f 47 while(1)
justinkim 0:e5950ca3f38f 48 {
justinkim 0:e5950ca3f38f 49 Heading = hmc5883l.getHeading();
justinkim 0:e5950ca3f38f 50
justinkim 0:e5950ca3f38f 51 pc.printf(" _______________\r\n");
justinkim 0:e5950ca3f38f 52 pc.printf("| Heading: %.1f \r\n", Heading);
justinkim 0:e5950ca3f38f 53 pc.printf("|_______________\r\n\r\n");
justinkim 0:e5950ca3f38f 54
justinkim 0:e5950ca3f38f 55 hmc5883l.readMagData(DataBuf);
justinkim 0:e5950ca3f38f 56
justinkim 0:e5950ca3f38f 57 pc.printf(" _______________\r\n");
justinkim 0:e5950ca3f38f 58 pc.printf("| MagXout: %.1f \r\n", DataBuf[0]);
justinkim 0:e5950ca3f38f 59 pc.printf("| MagYout: %.1f \r\n", DataBuf[1]);
justinkim 0:e5950ca3f38f 60 pc.printf("| MagZout: %.1f \r\n", DataBuf[2]);
justinkim 0:e5950ca3f38f 61 pc.printf("|_______________\r\n\r\n");
justinkim 0:e5950ca3f38f 62
justinkim 0:e5950ca3f38f 63 if(225>Heading && Heading>135)
justinkim 0:e5950ca3f38f 64 {
justinkim 0:e5950ca3f38f 65 myled_R1 = 0;
justinkim 0:e5950ca3f38f 66 myled_R2 = 0;
justinkim 0:e5950ca3f38f 67 myled_R3 = 0;
justinkim 0:e5950ca3f38f 68 myled_R4 = 0;
justinkim 0:e5950ca3f38f 69 myled_G1 = 1;
justinkim 0:e5950ca3f38f 70 myled_G2 = 1;
justinkim 0:e5950ca3f38f 71 myled_G3 = 1;
justinkim 0:e5950ca3f38f 72 myled_G4 = 1;
justinkim 0:e5950ca3f38f 73 myled_Y1 = 0;
justinkim 0:e5950ca3f38f 74 myled_Y2 = 0;
justinkim 0:e5950ca3f38f 75 myled_Y3 = 0;
justinkim 0:e5950ca3f38f 76 myled_Y4 = 0;
justinkim 0:e5950ca3f38f 77 }
justinkim 0:e5950ca3f38f 78
justinkim 0:e5950ca3f38f 79 else if(135>Heading && Heading>0)
justinkim 0:e5950ca3f38f 80 {
justinkim 0:e5950ca3f38f 81 myled_R1 = 1;
justinkim 0:e5950ca3f38f 82 myled_R2 = 1;
justinkim 0:e5950ca3f38f 83 myled_R3 = 1;
justinkim 0:e5950ca3f38f 84 myled_R4 = 1;
justinkim 0:e5950ca3f38f 85 myled_G1 = 0;
justinkim 0:e5950ca3f38f 86 myled_G2 = 0;
justinkim 0:e5950ca3f38f 87 myled_G3 = 0;
justinkim 0:e5950ca3f38f 88 myled_G4 = 0;
justinkim 0:e5950ca3f38f 89 myled_Y1 = 0;
justinkim 0:e5950ca3f38f 90 myled_Y2 = 0;
justinkim 0:e5950ca3f38f 91 myled_Y3 = 0;
justinkim 0:e5950ca3f38f 92 myled_Y4 = 0;
justinkim 0:e5950ca3f38f 93 }
justinkim 0:e5950ca3f38f 94 else if(360>Heading && Heading>225)
justinkim 0:e5950ca3f38f 95 {
justinkim 0:e5950ca3f38f 96 myled_R1 = 0;
justinkim 0:e5950ca3f38f 97 myled_R2 = 0;
justinkim 0:e5950ca3f38f 98 myled_R3 = 0;
justinkim 0:e5950ca3f38f 99 myled_R4 = 0;
justinkim 0:e5950ca3f38f 100 myled_G1 = 0;
justinkim 0:e5950ca3f38f 101 myled_G2 = 0;
justinkim 0:e5950ca3f38f 102 myled_G3 = 0;
justinkim 0:e5950ca3f38f 103 myled_G4 = 0;
justinkim 0:e5950ca3f38f 104 myled_Y1 = 1;
justinkim 0:e5950ca3f38f 105 myled_Y2 = 1;
justinkim 0:e5950ca3f38f 106 myled_Y3 = 1;
justinkim 0:e5950ca3f38f 107 myled_Y4 = 1;
justinkim 0:e5950ca3f38f 108 }
justinkim 0:e5950ca3f38f 109 }
justinkim 0:e5950ca3f38f 110 }
justinkim 0:e5950ca3f38f 111