![](/media/cache/group/218.jpg.50x50_q85.jpg)
via bluetooth uitlezen
Dependencies: mbed
Diff: main.cpp
- Revision:
- 1:351a8a56113a
- Parent:
- 0:1a51b2e26388
- Child:
- 2:1b827a164a4c
--- a/main.cpp Thu Jun 01 00:00:37 2017 +0000 +++ b/main.cpp Fri Jun 02 16:04:23 2017 +0000 @@ -5,24 +5,101 @@ // 9600 bauds, 8-bit data, no parity //------------------------------------ -Serial bt(D1, D0); +Serial bt(USBTX, USBRX); -DigitalOut myled(LED1); +AnalogIn linksvoor(A0); +AnalogIn rechtsvoor(A1); +AnalogIn linksachter(A2); +AnalogIn rechtsachter(A3); +AnalogIn afstand(A4); + +Ticker stepperspeed; + +DigitalOut steppulse(D9); + +DigitalOut enable(D10); + +DigitalIn button(D8); +DigitalOut led(D11); + +DigitalOut motorlfwd(D2); +DigitalOut motorlrwd(D3); +DigitalOut motorrfwd(D6); +DigitalOut motorrrwd(D7); + +float a; +float b; +float c; +float d; +float e; +float f; +float g; + +void setstep() +{ + steppulse = !steppulse; +} int main() { - int i = 1; +button.mode(PullUp); + // Init the ticker with the address of the function (toggle_led) to be attached and the interval (100 ms) + stepperspeed.attach(&setstep, 0.0008); + +led = 1; bt.printf("lekker draadloos pik !\n"); while(1) { - wait(1); - bt.printf("This program runs since %d seconds.\n", i++); - myled = !myled; + wait(0.05); + a = afstand; + b = linksvoor; + c = rechtsvoor; + d = linksachter; + e = rechtsachter; + + bt.printf("dis = %f, FL = %f, FR = %f, RL = %f, RR = %f.\n", a, b, c, d, e); + if (bt.readable() > 0) { -char c = bt.getc(); - bt.printf("stopped\n"); - + char c = bt.getc(); + switch(c){ + case 's': + bt.printf("stopped\n"); + + motorlfwd = 0; + motorrfwd = 0; + motorlrwd = 0; + motorrrwd = 0; + enable = 1; + led = 0; + break; + case 'q': + bt.printf("LFWD\n"); + motorlfwd = 1; + break; + case 'w': + bt.printf("RFWD\n"); + motorrfwd = 1; + break; + case 'e': + bt.printf("LRWD\n"); + motorlrwd = 1; + break; + case 'r': + bt.printf("RRWD\n"); + motorrrwd = 1; + break; + case 'a': + bt.printf("Stepper\n"); + enable = 0; + break; + case 'd': + bt.printf("led\n"); + led = 1; + break; + } + + } }