![](/media/cache/group/218.jpg.50x50_q85.jpg)
via bluetooth uitlezen
Dependencies: mbed
main.cpp@2:1b827a164a4c, 2017-06-04 (annotated)
- Committer:
- joosthartkamp
- Date:
- Sun Jun 04 11:57:44 2017 +0000
- Revision:
- 2:1b827a164a4c
- Parent:
- 1:351a8a56113a
klaar
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
joosthartkamp | 0:1a51b2e26388 | 1 | #include "mbed.h" |
joosthartkamp | 0:1a51b2e26388 | 2 | |
joosthartkamp | 0:1a51b2e26388 | 3 | //------------------------------------ |
joosthartkamp | 0:1a51b2e26388 | 4 | // Hyperterminal configuration |
joosthartkamp | 0:1a51b2e26388 | 5 | // 9600 bauds, 8-bit data, no parity |
joosthartkamp | 0:1a51b2e26388 | 6 | //------------------------------------ |
joosthartkamp | 0:1a51b2e26388 | 7 | |
joosthartkamp | 1:351a8a56113a | 8 | Serial bt(USBTX, USBRX); |
joosthartkamp | 0:1a51b2e26388 | 9 | |
joosthartkamp | 0:1a51b2e26388 | 10 | |
joosthartkamp | 1:351a8a56113a | 11 | AnalogIn linksvoor(A0); |
joosthartkamp | 1:351a8a56113a | 12 | AnalogIn rechtsvoor(A1); |
joosthartkamp | 1:351a8a56113a | 13 | AnalogIn linksachter(A2); |
joosthartkamp | 1:351a8a56113a | 14 | AnalogIn rechtsachter(A3); |
joosthartkamp | 1:351a8a56113a | 15 | AnalogIn afstand(A4); |
joosthartkamp | 1:351a8a56113a | 16 | |
joosthartkamp | 1:351a8a56113a | 17 | Ticker stepperspeed; |
joosthartkamp | 1:351a8a56113a | 18 | |
joosthartkamp | 1:351a8a56113a | 19 | DigitalOut steppulse(D9); |
joosthartkamp | 1:351a8a56113a | 20 | |
joosthartkamp | 2:1b827a164a4c | 21 | DigitalOut enable(D7); |
joosthartkamp | 1:351a8a56113a | 22 | |
joosthartkamp | 1:351a8a56113a | 23 | DigitalIn button(D8); |
joosthartkamp | 1:351a8a56113a | 24 | DigitalOut led(D11); |
joosthartkamp | 1:351a8a56113a | 25 | |
joosthartkamp | 0:1a51b2e26388 | 26 | |
joosthartkamp | 1:351a8a56113a | 27 | DigitalOut motorlfwd(D2); |
joosthartkamp | 1:351a8a56113a | 28 | DigitalOut motorlrwd(D3); |
joosthartkamp | 1:351a8a56113a | 29 | DigitalOut motorrfwd(D6); |
joosthartkamp | 2:1b827a164a4c | 30 | DigitalOut motorrrwd(D10); |
joosthartkamp | 1:351a8a56113a | 31 | |
joosthartkamp | 1:351a8a56113a | 32 | float a; |
joosthartkamp | 1:351a8a56113a | 33 | float b; |
joosthartkamp | 1:351a8a56113a | 34 | float c; |
joosthartkamp | 1:351a8a56113a | 35 | float d; |
joosthartkamp | 1:351a8a56113a | 36 | float e; |
joosthartkamp | 1:351a8a56113a | 37 | float f; |
joosthartkamp | 1:351a8a56113a | 38 | float g; |
joosthartkamp | 1:351a8a56113a | 39 | |
joosthartkamp | 1:351a8a56113a | 40 | void setstep() |
joosthartkamp | 1:351a8a56113a | 41 | { |
joosthartkamp | 1:351a8a56113a | 42 | steppulse = !steppulse; |
joosthartkamp | 1:351a8a56113a | 43 | } |
joosthartkamp | 0:1a51b2e26388 | 44 | |
joosthartkamp | 0:1a51b2e26388 | 45 | int main() |
joosthartkamp | 0:1a51b2e26388 | 46 | { |
joosthartkamp | 1:351a8a56113a | 47 | button.mode(PullUp); |
joosthartkamp | 1:351a8a56113a | 48 | // Init the ticker with the address of the function (toggle_led) to be attached and the interval (100 ms) |
joosthartkamp | 1:351a8a56113a | 49 | stepperspeed.attach(&setstep, 0.0008); |
joosthartkamp | 1:351a8a56113a | 50 | |
joosthartkamp | 1:351a8a56113a | 51 | led = 1; |
joosthartkamp | 0:1a51b2e26388 | 52 | bt.printf("lekker draadloos pik !\n"); |
joosthartkamp | 0:1a51b2e26388 | 53 | while(1) { |
joosthartkamp | 1:351a8a56113a | 54 | wait(0.05); |
joosthartkamp | 1:351a8a56113a | 55 | a = afstand; |
joosthartkamp | 1:351a8a56113a | 56 | b = linksvoor; |
joosthartkamp | 1:351a8a56113a | 57 | c = rechtsvoor; |
joosthartkamp | 1:351a8a56113a | 58 | d = linksachter; |
joosthartkamp | 1:351a8a56113a | 59 | e = rechtsachter; |
joosthartkamp | 1:351a8a56113a | 60 | |
joosthartkamp | 1:351a8a56113a | 61 | bt.printf("dis = %f, FL = %f, FR = %f, RL = %f, RR = %f.\n", a, b, c, d, e); |
joosthartkamp | 1:351a8a56113a | 62 | |
joosthartkamp | 0:1a51b2e26388 | 63 | if (bt.readable() > 0) { |
joosthartkamp | 1:351a8a56113a | 64 | char c = bt.getc(); |
joosthartkamp | 1:351a8a56113a | 65 | switch(c){ |
joosthartkamp | 1:351a8a56113a | 66 | case 's': |
joosthartkamp | 1:351a8a56113a | 67 | bt.printf("stopped\n"); |
joosthartkamp | 1:351a8a56113a | 68 | |
joosthartkamp | 1:351a8a56113a | 69 | motorlfwd = 0; |
joosthartkamp | 1:351a8a56113a | 70 | motorrfwd = 0; |
joosthartkamp | 1:351a8a56113a | 71 | motorlrwd = 0; |
joosthartkamp | 1:351a8a56113a | 72 | motorrrwd = 0; |
joosthartkamp | 1:351a8a56113a | 73 | enable = 1; |
joosthartkamp | 1:351a8a56113a | 74 | led = 0; |
joosthartkamp | 1:351a8a56113a | 75 | break; |
joosthartkamp | 1:351a8a56113a | 76 | case 'q': |
joosthartkamp | 1:351a8a56113a | 77 | bt.printf("LFWD\n"); |
joosthartkamp | 1:351a8a56113a | 78 | motorlfwd = 1; |
joosthartkamp | 1:351a8a56113a | 79 | break; |
joosthartkamp | 1:351a8a56113a | 80 | case 'w': |
joosthartkamp | 1:351a8a56113a | 81 | bt.printf("RFWD\n"); |
joosthartkamp | 1:351a8a56113a | 82 | motorrfwd = 1; |
joosthartkamp | 1:351a8a56113a | 83 | break; |
joosthartkamp | 1:351a8a56113a | 84 | case 'e': |
joosthartkamp | 1:351a8a56113a | 85 | bt.printf("LRWD\n"); |
joosthartkamp | 1:351a8a56113a | 86 | motorlrwd = 1; |
joosthartkamp | 1:351a8a56113a | 87 | break; |
joosthartkamp | 1:351a8a56113a | 88 | case 'r': |
joosthartkamp | 1:351a8a56113a | 89 | bt.printf("RRWD\n"); |
joosthartkamp | 1:351a8a56113a | 90 | motorrrwd = 1; |
joosthartkamp | 1:351a8a56113a | 91 | break; |
joosthartkamp | 1:351a8a56113a | 92 | case 'a': |
joosthartkamp | 1:351a8a56113a | 93 | bt.printf("Stepper\n"); |
joosthartkamp | 1:351a8a56113a | 94 | enable = 0; |
joosthartkamp | 1:351a8a56113a | 95 | break; |
joosthartkamp | 1:351a8a56113a | 96 | case 'd': |
joosthartkamp | 1:351a8a56113a | 97 | bt.printf("led\n"); |
joosthartkamp | 1:351a8a56113a | 98 | led = 1; |
joosthartkamp | 1:351a8a56113a | 99 | break; |
joosthartkamp | 1:351a8a56113a | 100 | } |
joosthartkamp | 1:351a8a56113a | 101 | |
joosthartkamp | 1:351a8a56113a | 102 | |
joosthartkamp | 0:1a51b2e26388 | 103 | |
joosthartkamp | 0:1a51b2e26388 | 104 | } |
joosthartkamp | 0:1a51b2e26388 | 105 | } |
joosthartkamp | 0:1a51b2e26388 | 106 | |
joosthartkamp | 0:1a51b2e26388 | 107 | } |