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.
main.cpp@2:229242a63331, 2019-01-31 (annotated)
- Committer:
- hisyamfs
- Date:
- Thu Jan 31 12:15:20 2019 +0000
- Revision:
- 2:229242a63331
- Parent:
- 1:4100c0aeb0d7
- Child:
- 3:892567359899
blah
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| hisyamfs | 0:5cf249ca41f0 | 1 | #include "mbed.h" |
| hisyamfs | 0:5cf249ca41f0 | 2 | |
| hisyamfs | 2:229242a63331 | 3 | #define I2C_ADDR 0xC0 |
| hisyamfs | 0:5cf249ca41f0 | 4 | #define WR 0 |
| hisyamfs | 0:5cf249ca41f0 | 5 | #define RD 1 |
| hisyamfs | 0:5cf249ca41f0 | 6 | |
| hisyamfs | 0:5cf249ca41f0 | 7 | I2C cmps12(D14, D15); //sda, scl |
| hisyamfs | 0:5cf249ca41f0 | 8 | DigitalOut led(LED1); |
| hisyamfs | 0:5cf249ca41f0 | 9 | Serial pc(USBTX, USBRX); |
| hisyamfs | 0:5cf249ca41f0 | 10 | |
| hisyamfs | 0:5cf249ca41f0 | 11 | int main() |
| hisyamfs | 0:5cf249ca41f0 | 12 | { |
| hisyamfs | 0:5cf249ca41f0 | 13 | led = 0; |
| hisyamfs | 0:5cf249ca41f0 | 14 | char data[2]; |
| hisyamfs | 2:229242a63331 | 15 | data[0] = 0x1; |
| hisyamfs | 1:4100c0aeb0d7 | 16 | data[1] = 0xFF; |
| hisyamfs | 0:5cf249ca41f0 | 17 | pc.printf("Started scanning\n"); |
| hisyamfs | 0:5cf249ca41f0 | 18 | int nack = 1; |
| hisyamfs | 1:4100c0aeb0d7 | 19 | while(1) |
| hisyamfs | 0:5cf249ca41f0 | 20 | { |
| hisyamfs | 1:4100c0aeb0d7 | 21 | nack = cmps12.write(I2C_ADDR, data, 1); |
| hisyamfs | 2:229242a63331 | 22 | // if (nack) { |
| hisyamfs | 2:229242a63331 | 23 | // pc.printf("Gak nyambung nulis %d\n", nack); |
| hisyamfs | 2:229242a63331 | 24 | // } |
| hisyamfs | 2:229242a63331 | 25 | // else { |
| hisyamfs | 1:4100c0aeb0d7 | 26 | nack = cmps12.read(I2C_ADDR, data+1, 1); |
| hisyamfs | 2:229242a63331 | 27 | // if (nack) { |
| hisyamfs | 2:229242a63331 | 28 | // pc.printf("Gak nyambung baca %d\n", nack); |
| hisyamfs | 2:229242a63331 | 29 | // } |
| hisyamfs | 2:229242a63331 | 30 | // else { |
| hisyamfs | 2:229242a63331 | 31 | pc.printf("Bearing = %.2f\n", (float) data[1]/255*360); |
| hisyamfs | 2:229242a63331 | 32 | // } |
| hisyamfs | 2:229242a63331 | 33 | // } |
| hisyamfs | 2:229242a63331 | 34 | wait(0.5); |
| hisyamfs | 0:5cf249ca41f0 | 35 | } |
| hisyamfs | 0:5cf249ca41f0 | 36 | } |