final
Dependencies: Servo TSI mbed-rtos mbed
Revision 0:ab66364231c8, committed 2016-12-02
- Comitter:
- backman
- Date:
- Fri Dec 02 13:06:19 2016 +0000
- Commit message:
- final
Changed in this revision
diff -r 000000000000 -r ab66364231c8 Servo.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Servo.lib Fri Dec 02 13:06:19 2016 +0000 @@ -0,0 +1,1 @@ +https://developer.mbed.org/users/backman/code/Servo/#b9fe7af92cd5
diff -r 000000000000 -r ab66364231c8 TSI.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TSI.lib Fri Dec 02 13:06:19 2016 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/TSI/#1a60ef257879
diff -r 000000000000 -r ab66364231c8 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Fri Dec 02 13:06:19 2016 +0000 @@ -0,0 +1,153 @@ +#include "mbed.h" +#include "Servo.h" +#include "TSISensor.h" +#include "rtos.h" +DigitalOut ledR(LED1); +DigitalOut ledG(LED2); +DigitalOut ledB(LED3); + +I2CSlave slave(PTE0,PTE1); +Servo s(PTB0); + + + +TSISensor tsi; + + + bool strCmp(char*a, char*b){ + + + + int ptr=0; + bool flag=true; + for(;a[ptr]!='\0'||b[ptr]!='\0';ptr++){ + if(a[ptr]!=b[ptr]){ + flag=false; + break; + } + } + + + return flag; + +} + + +void ledCtl(char* str){ + + if(strCmp(str,"R")){ + ledR=0; + + } + else if(strCmp(str,"G")) + ledG=0; + else if(strCmp(str,"B")) + ledB=0; + else if(strCmp(str,"T")) + ledR=1; + else if(strCmp(str,"H")) + ledG=1; + else if(strCmp(str,"N")) + ledB=1; + else{ + ledR=ledG=ledB=1; + + } + + } + + +void servoCtl(char* str){ + float ang= (float) str[0]; + s.angle(ang); + + + } + + + +void ble_i2c(void const *args) { + + char buf[20]; + char msg[] = "Backman!"; + slave.address(0xBA); + + + while (true) { + + int i = slave.receive(); + switch (i) { + case I2CSlave::ReadAddressed: + slave.write(msg, strlen(msg) + 1); // Includes null char + break; + case I2CSlave::WriteGeneral: + slave.read(buf, 20); + printf("Read G: %s\n", buf); + break; + case I2CSlave::WriteAddressed: + + slave.read(buf, 20); + //ledCtl(buf); + servoCtl(buf); + printf("Read A: %s\r\n", buf); + break; + } + for(int i = 0; i < 20; i++) buf[i] = 0; // Clear buffer + + Thread::wait(50); + } + + + +} + + + + + + + +int main() { + + + ledR=ledG=ledB=1; + // Thread thread(ble_i2c); + + s.angle(0); + + char buf[20]; + char msg[] = "Backman!"; + slave.address(0xBA); + + + while (true) { + + int i = slave.receive(); + switch (i) { + case I2CSlave::ReadAddressed: + slave.write(msg, strlen(msg) + 1); // Includes null char + break; + case I2CSlave::WriteGeneral: + slave.read(buf, 20); + printf("Read G: %s\n", buf); + break; + case I2CSlave::WriteAddressed: + + slave.read(buf, 20); + //ledCtl(buf); + servoCtl(buf); + printf("Read A: %s\r\n", buf); + break; + } + for(int i = 0; i < 20; i++) buf[i] = 0; // Clear buffer + + + } + + + + + return 0; + + + } \ No newline at end of file
diff -r 000000000000 -r ab66364231c8 mbed-rtos.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-rtos.lib Fri Dec 02 13:06:19 2016 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed-rtos/#5aed8bae1001
diff -r 000000000000 -r ab66364231c8 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Fri Dec 02 13:06:19 2016 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/b9ad9a133dc7 \ No newline at end of file