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: MotionSensor mbed
Fork of MAG3110 by
main.cpp@7:a8a59a2b6cf6, 2017-01-12 (annotated)
- Committer:
- Nike3221
- Date:
- Thu Jan 12 05:21:13 2017 +0000
- Revision:
- 7:a8a59a2b6cf6
- Child:
- 8:c8512336fa70
MAG3110
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| Nike3221 | 7:a8a59a2b6cf6 | 1 | /* |
| Nike3221 | 7:a8a59a2b6cf6 | 2 | * MAG3110 Sensor Library for mbed |
| Nike3221 | 7:a8a59a2b6cf6 | 3 | * TODO: Add proper header |
| Nike3221 | 7:a8a59a2b6cf6 | 4 | */ |
| Nike3221 | 7:a8a59a2b6cf6 | 5 | |
| Nike3221 | 7:a8a59a2b6cf6 | 6 | |
| Nike3221 | 7:a8a59a2b6cf6 | 7 | #include "mbed.h" |
| Nike3221 | 7:a8a59a2b6cf6 | 8 | #include "MotionSensor.h" |
| Nike3221 | 7:a8a59a2b6cf6 | 9 | #include "MAG3110.h" |
| Nike3221 | 7:a8a59a2b6cf6 | 10 | |
| Nike3221 | 7:a8a59a2b6cf6 | 11 | Serial pc(USBTX,USBRX); |
| Nike3221 | 7:a8a59a2b6cf6 | 12 | int16_t x,y,z; |
| Nike3221 | 7:a8a59a2b6cf6 | 13 | LocalFileSystem local("local"); |
| Nike3221 | 7:a8a59a2b6cf6 | 14 | |
| Nike3221 | 7:a8a59a2b6cf6 | 15 | MAG3110 mag(p28,p27); |
| Nike3221 | 7:a8a59a2b6cf6 | 16 | |
| Nike3221 | 7:a8a59a2b6cf6 | 17 | |
| Nike3221 | 7:a8a59a2b6cf6 | 18 | |
| Nike3221 | 7:a8a59a2b6cf6 | 19 | int main(){ |
| Nike3221 | 7:a8a59a2b6cf6 | 20 | while(1){ |
| Nike3221 | 7:a8a59a2b6cf6 | 21 | mag.enable(); |
| Nike3221 | 7:a8a59a2b6cf6 | 22 | //void disable(void); |
| Nike3221 | 7:a8a59a2b6cf6 | 23 | mag.sampleRate(0x80); |
| Nike3221 | 7:a8a59a2b6cf6 | 24 | //uint32_t whoAmI(void); |
| Nike3221 | 7:a8a59a2b6cf6 | 25 | //uint32_t dataReady(void); |
| Nike3221 | 7:a8a59a2b6cf6 | 26 | mag.getX(&x); |
| Nike3221 | 7:a8a59a2b6cf6 | 27 | mag.getY(&y); |
| Nike3221 | 7:a8a59a2b6cf6 | 28 | mag.getZ(&z); |
| Nike3221 | 7:a8a59a2b6cf6 | 29 | //void getX(float * x); |
| Nike3221 | 7:a8a59a2b6cf6 | 30 | //void getY(float * y); |
| Nike3221 | 7:a8a59a2b6cf6 | 31 | //void getZ(float * z); |
| Nike3221 | 7:a8a59a2b6cf6 | 32 | //void getAxis(MotionSensorDataCounts &data); |
| Nike3221 | 7:a8a59a2b6cf6 | 33 | //void getAxis(MotionSensorDataUnits &data); |
| Nike3221 | 7:a8a59a2b6cf6 | 34 | //void readRegs(int addr, uint8_t * data, int len); |
| Nike3221 | 7:a8a59a2b6cf6 | 35 | pc.printf("x: %d y: %d z: %d\n",x,y,z); |
| Nike3221 | 7:a8a59a2b6cf6 | 36 | |
| Nike3221 | 7:a8a59a2b6cf6 | 37 | FILE *fp = fopen("/local/commpas_new.txt","a"); |
| Nike3221 | 7:a8a59a2b6cf6 | 38 | fprintf(fp,"%d,%d,%d\n",x,y,z); |
| Nike3221 | 7:a8a59a2b6cf6 | 39 | fclose(fp);} |
| Nike3221 | 7:a8a59a2b6cf6 | 40 | } |
