Jose R Padron
/
Hello_World_HMC5843
HMC5843 Hello World example
Embed:
(wiki syntax)
Show/hide line numbers
main.cpp
00001 #include "HMC5843.h" 00002 00003 HMC5843 compass(p28, p27); 00004 Serial pc(USBTX, USBRX); 00005 00006 //Magnetics values x,y,z 00007 int readings[3]; 00008 00009 //ID Buffer 00010 char buffer[3]; 00011 00012 00013 int main() { 00014 00015 pc.printf("Starting HMC5843 test...%c%c",13,10); 00016 00017 //ID should be H43 00018 compass.getAddress(buffer); 00019 pc.printf("Magnetic Compass Id=%c%c%c \n\r",buffer[0],buffer[1],buffer[2]); 00020 00021 //Continuous mode, , 10Hz measurement rate. 00022 // HMC5843_CONTINUOUS, HMC5843_10HZ_NORMAL HMC5843_1_0GA 00023 compass.setDefault(); 00024 00025 //Wait some time(Need at least 5ms) 00026 wait(.1); 00027 00028 00029 while(1){ 00030 00031 00032 compass.readData(readings); 00033 00034 pc.printf("Magnetic Values Mx=%i, My=%i and Mz=%i %c%c",(int16_t)readings[0],(int16_t)readings[1],(int16_t)readings[2] ,13,10); 00035 00036 wait(0.1); 00037 00038 00039 00040 } 00041 00042 }
Generated on Thu Jul 14 2022 02:00:35 by 1.7.2