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:
- 2:96f52163ca48
- Parent:
- 1:11ff92032e78
- Child:
- 3:80ceedd5ffac
diff -r 11ff92032e78 -r 96f52163ca48 main.cpp
--- a/main.cpp Fri Jan 15 16:03:49 2016 +0000
+++ b/main.cpp Mon Jan 18 15:47:53 2016 +0000
@@ -8,33 +8,73 @@
DigitalOut led3(LED3);
DigitalOut led4(LED4);
-const int addr = 0x38;
-
int main(){
char data_write[2];
- //char data_read[2];
led1 = 1;
led2 = 1;
led3 = 1;
led4 = 1;
- data_write[0] = 0x01;
- data_write[1] = 0x00;
- //i2c.start();
- int status = i2c.write(addr,data_write, 2);
+ data_write[0] = 0x00;
+
+ i2c.frequency(400000);
+ i2c.start();
+
+ i2c.write(0xAA, data_write, 1);
+
+ char data_read[7];
+ i2c.read(0xAB, data_read, 7, true);
+
+ if(data_read[0] == 0)
+ led1 = 0;
- if (status != 0) { // Error
+ if(data_read[1] == 0)
+ led2 = 0;
+
+ if(data_read[2] == 0)
+ led3 = 0;
+
+ if(data_read[3] == 0)
+ led4 = 0;
+
+ i2c.stop();
+
+ //data_write[0] = 0x01;
+ //data_write[1] = 0x00;
+ //i2c.start();
+ //int status = i2c.write(addr,data_write, 2);
+
+ /*if (status != 0) { // Error
while (1) {
- led4 = !led4;
- wait(0.2);
+
}
- }
+ } */
+
+ //bool haPasado = false;
+
+ //i2c.frequency(200000);
/*while(1){
+
+ i2c.start();
+
+ wait(0.5);
+
+ int status = i2c.read(addr, data_read, 3);
+
+ if (status == 0)
+ haPasado = true;
+
+ if (!haPasado)
+ led4 = !led4;
+
+ i2c.stop();
+
+ }*/
//i2c.start();
- data_write[0] = 0x00;
+ /*data_write[0] = 0x00;
i2c.write(addr, data_write, 1,1);
i2c.read(addr, data_read, 2,0);
