kodingan penjelasan

Embed Size (px)

Citation preview

  • 7/24/2019 kodingan penjelasan

    1/3

    #include //library wire ini memungkinkan kita untuk

    berkomunikasi dengan I2C/TWI

    perangkat. pada papan arduino ! yaitu terletak

    "I$ pin out% &'(")alur

    data% dan &C* ")am *ine%

    #include //library ini memungkinkan kita mengetahui isi

    pada tiap sensor

    #include

    / (ssign a uni3ue I' to this sensor at the same time /

    (da+ruit,-C00!,1ni4ed mag 5 (da+ruit,-C00!,1ni4ed"62!7%8

    /// 9ow take a compass reading to supplement :;& in+ormation

    int y=8 //triple ais data/

    /char nmeastr6?@8 // -C-':AAA.AA

    int checksum8char hsB@8 // AAA.AA

    /

    oid display&ensor'etails"oid%

    D

    sensor,t sensor8

    mag.get&ensor"Esensor%8

    / &erial.println"FGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGF%8

    &erial.print "F&ensorH F%8 &erial.println"sensor.name%8

    &erial.print "F'rier erH F%8 &erial.println"sensor.ersion%8

    &erial.print "F1ni3ue I'H F%8 &erial.println"sensor.sensor,id%8 &erial.print "Fa alueH F%8 &erial.print"sensor.ma,alue%8 &erial.println"F

    uTF%8

    &erial.print "Fin alueH F%8 &erial.print"sensor.min,alue%8 &erial.println"F

    uTF%8

    &erial.print "FesolutionH F%8 &erial.print"sensor.resolution%8 &erial.println"F

    uTF%8

    &erial.println"FGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGF%8

    &erial.println"FF%8/

    delay"AA%8

    J

    oid setup"oid%

    D

    &erial.begin"KBAA%8

    / &erial.println"F-C00! agnetometer TestF%8 &erial.println"FF%8

    / Initialise the sensor /

    /i+"Lmag.begin"%%

    D

    / There was a problem detecting the -C00! ... check your connections / / &erial.println"F$oops no -C00! detected ... Check your wiringLF%8

  • 7/24/2019 kodingan penjelasan

    2/3

    while"6%8

    J/

    / 'isplay some basic in+ormation on this sensor /

    display&ensor'etails"%8

    J

    oid loop"oid%

    D

    / :et a new sensor eent /

    sensors,eent,t eent8

    mag.getMent"Eeent%8

    / 'isplay the results "magnetic ector alues are in microGTesla "uT%% /

    &erial.print"FN-C-':F%8&erial.print"FF%8 &erial.print"eent.magnetic.%8

    &erial.print"FF%8 &erial.print"eent.magnetic.y%8 &erial.print"FF%8

    &erial.print"eent.magnetic.=%8 &erial.print"FF%8//&erial.print"FuTF%8

    // -old the module so that O is pointing PupP and you can measure the heading

    with Ey

    // Calculate heading when the magnetometer is leel then correct +or signs o+

    ais.

    Qoat heading 5 atan2"eent.magnetic.y eent.magnetic.%8

    // $nce you hae your heading you must then add your P'eclination (ngleP

    which is the PMrrorP o+ the magnetic 4eld in your location. // Rind yours hereH httpH//www.magneticGdeclination.com/

    // ine isH G6! 2P W which is S6! 'egrees or "which we need% A.22 radians

    // I+ you cannot 4nd your 'eclination comment out these two lines your

    compass will be slightly o.

    Qoat declination(ngle 5 A.228

    heading U5 declination(ngle8

    // Correct +or when signs are reersed.

    i+"heading < A%

    heading U5 2;I8

    // Check +or wrap due to addition o+ declination.

    i+"heading > 2;I%

    heading G5 2;I8

    // Conert radians to degrees +or readability.

    Qoat heading'egrees 5 heading 60A/,;I8

    &erial.print"heading'egrees%8&erial.print"FF%8&erial.println"F62F%8

  • 7/24/2019 kodingan penjelasan

    3/3

    //delay"AA%8

    J