control de servo con bt
Dependencies: Servo SoftSerial mbed
main.cpp@0:2acb15ba6059, 2017-10-07 (annotated)
- Committer:
- briandk
- Date:
- Sat Oct 07 21:56:14 2017 +0000
- Revision:
- 0:2acb15ba6059
- Child:
- 1:998b1ef95a89
control de servo mediante bluethoot
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
briandk | 0:2acb15ba6059 | 1 | #include "mbed.h" |
briandk | 0:2acb15ba6059 | 2 | #include "SoftSerial.h" |
briandk | 0:2acb15ba6059 | 3 | //#include "Servo.h" |
briandk | 0:2acb15ba6059 | 4 | |
briandk | 0:2acb15ba6059 | 5 | PwmOut servo(PB_5); |
briandk | 0:2acb15ba6059 | 6 | Serial pc (USBTX,USBRX); |
briandk | 0:2acb15ba6059 | 7 | SoftSerial bt (D2,D3); |
briandk | 0:2acb15ba6059 | 8 | |
briandk | 0:2acb15ba6059 | 9 | char receive; |
briandk | 0:2acb15ba6059 | 10 | float vel; |
briandk | 0:2acb15ba6059 | 11 | |
briandk | 0:2acb15ba6059 | 12 | int main() |
briandk | 0:2acb15ba6059 | 13 | { |
briandk | 0:2acb15ba6059 | 14 | |
briandk | 0:2acb15ba6059 | 15 | |
briandk | 0:2acb15ba6059 | 16 | while (1) |
briandk | 0:2acb15ba6059 | 17 | { |
briandk | 0:2acb15ba6059 | 18 | if (bt.readable()>0) |
briandk | 0:2acb15ba6059 | 19 | { |
briandk | 0:2acb15ba6059 | 20 | |
briandk | 0:2acb15ba6059 | 21 | receive=bt.getc(); |
briandk | 0:2acb15ba6059 | 22 | vel=receive-48; |
briandk | 0:2acb15ba6059 | 23 | vel/=10; |
briandk | 0:2acb15ba6059 | 24 | pc.printf("%c %f\n\r",receive,vel); |
briandk | 0:2acb15ba6059 | 25 | servo.write(vel); |
briandk | 0:2acb15ba6059 | 26 | |
briandk | 0:2acb15ba6059 | 27 | |
briandk | 0:2acb15ba6059 | 28 | |
briandk | 0:2acb15ba6059 | 29 | } |
briandk | 0:2acb15ba6059 | 30 | } |
briandk | 0:2acb15ba6059 | 31 | |
briandk | 0:2acb15ba6059 | 32 | } |
briandk | 0:2acb15ba6059 | 33 |