test
Dependencies: mbed Motordriver SRF05
Diff: main.cpp
- Revision:
- 3:6484736ff515
- Parent:
- 2:ff7c5f9ba765
- Child:
- 4:79adbd22ee27
--- a/main.cpp Thu Dec 08 13:49:21 2016 +0000 +++ b/main.cpp Fri Dec 09 11:55:50 2016 +0000 @@ -1,6 +1,8 @@ #include "mbed.h" #include <string> #include <cstring> +//#include "rtos.h" +#include "motordriver.h" Serial bt(p28,p27);//tx,rx Serial TAG(p9,p10);//tx,rx Serial pc(USBTX,USBRX); @@ -8,6 +10,7 @@ void read_line(); void Rx_interrupt(); +void move(char in); // Circular buffers for serial TX and RX data - used by interrupt routines const int buffer_size = 255; // might need to increase buffer size for high baud rates @@ -20,6 +23,50 @@ bool flag1=false, flag2=false, flag3=false; string str; +Motor L(p21, p23, p22, 1); // pwm, fwd, rev, can brake ,right +Motor R(p26, p24, p25, 1); // pwm, fwd, rev, can brake ,left + + +void move(char in){ + char ch[1]={'s'}; + ch[0] = in; + // while(1) { + //pc.printf("ch[0]= %s\n\r",ch); + /* if(bt.readable ()){ + ch[0]=bt.getc(); + //pc.printf("string1 = %s\n\r",ch); + } */ + switch(ch[0]){ + case 'w': + //前進 + R.speed(0.7),L.speed(1); + break; + case 'a': + //左轉 + R.speed(0.7),L.speed(0); + break; + case 's': + //停住 + R.stop(0.3),L.stop(0.3); + break; + case 'd': + //右轉 + R.speed(0),L.speed(0.711qqqa); + break; + case 'x': + //backward + R.speed(-0.7),L.speed(-1); + break; + case 'm': + //自走車 + break; + } + // } + + + + +} //std::string. int main() { bt.baud(38400); @@ -29,8 +76,10 @@ bt.printf("bt hello\n\r"); TAG.attach(&Rx_interrupt, Serial::RxIrq); - - + char ch = 's' ; + //Thread thread(move_thread); + //thread.set_priority(osPriorityLow); + while(1) { @@ -64,6 +113,15 @@ bt.printf("%s\n",str); } + + if(bt.readable()) + ch=bt.getc(); + move(ch); + + + + + } } // Read a line from the large rx buffer from rx interrupt routine