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: BLE_API mbed nRF51822 circular_buffer
Diff: main.cpp
- Revision:
- 3:80ceedd5ffac
- Parent:
- 2:96f52163ca48
- Child:
- 4:a743917cd04c
--- a/main.cpp Mon Jan 18 15:47:53 2016 +0000
+++ b/main.cpp Mon Jan 18 16:26:04 2016 +0000
@@ -17,12 +17,54 @@
led3 = 1;
led4 = 1;
- data_write[0] = 0x00;
+ i2c.frequency(400000);
+
+ while(1){
+
+ data_write[0] = 0x00;
+
+ i2c.start();
+
+ i2c.write(0xAB, data_write, 1);
+
+ char data_read[7];
+ i2c.read(0xAA, data_read, 7, true);
+
+ if(data_read[0] == 0)
+ led1 = 0;
+
+ int ch0 =(data_read[1] << 6) | data_read[2] >> 2;
+
+ if(ch0 < 0x00FF) //X
+ led2 = 0;
+ else
+ led2 = 1;
+
+ int ch1 =(data_read[3] << 6) | data_read[4] >> 2;
+
+ if(ch1 < 0x00FF) //Y
+ led3 = 0;
+ else
+ led3 = 1;
+
+ int ch2 =(data_read[5] << 6) | data_read[6] >> 2;
+
+ if(ch2 < 0x00FF) //Z
+ led4 = 0;
+ else
+ led4 = 1;
+
+ /*led1 = 1;
+ led2 = 1;
+ led3 = 1;
+ led4 = 1;*/
+
+ i2c.stop();
+
+ wait(0.2);
+ }
- i2c.frequency(400000);
- i2c.start();
-
- i2c.write(0xAA, data_write, 1);
+ /*i2c.write(0xAA, data_write, 1);
char data_read[7];
i2c.read(0xAB, data_read, 7, true);
@@ -39,7 +81,7 @@
if(data_read[3] == 0)
led4 = 0;
- i2c.stop();
+ i2c.stop();*/
//data_write[0] = 0x01;
//data_write[1] = 0x00;
