Diplomarbeit_blimp
/
bluetooth_0110
bluetooth_0110
Fork of bluetooth_0110 by
main.cpp@0:11047e265142, 2015-10-01 (annotated)
- Committer:
- andreashatzl
- Date:
- Thu Oct 01 18:18:46 2015 +0000
- Revision:
- 0:11047e265142
bluetoothansteuerung motor
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
andreashatzl | 0:11047e265142 | 1 | |
andreashatzl | 0:11047e265142 | 2 | #include "mbed.h" |
andreashatzl | 0:11047e265142 | 3 | #include "Serial_HL.h" |
andreashatzl | 0:11047e265142 | 4 | |
andreashatzl | 0:11047e265142 | 5 | // Testprogramm um zu sehen ob die RGB-Led richtig verlötet |
andreashatzl | 0:11047e265142 | 6 | // ist und ob sie sich auch dimmen lässt |
andreashatzl | 0:11047e265142 | 7 | |
andreashatzl | 0:11047e265142 | 8 | SerialBLK pc(USBTX, USBRX); |
andreashatzl | 0:11047e265142 | 9 | SvProtocol ua0(&pc); |
andreashatzl | 0:11047e265142 | 10 | |
andreashatzl | 0:11047e265142 | 11 | PwmOut servo1(p21),servo2(p22),servo3(p23); |
andreashatzl | 0:11047e265142 | 12 | SerialBLK blue(p9, p10); |
andreashatzl | 0:11047e265142 | 13 | int16_t stickVal1,stickVal2,stickVal3; |
andreashatzl | 0:11047e265142 | 14 | |
andreashatzl | 0:11047e265142 | 15 | void CommandHandler(); |
andreashatzl | 0:11047e265142 | 16 | |
andreashatzl | 0:11047e265142 | 17 | int main() |
andreashatzl | 0:11047e265142 | 18 | { |
andreashatzl | 0:11047e265142 | 19 | servo1.period_ms(20); |
andreashatzl | 0:11047e265142 | 20 | servo2.period_ms(20); |
andreashatzl | 0:11047e265142 | 21 | servo3.period_ms(20); |
andreashatzl | 0:11047e265142 | 22 | |
andreashatzl | 0:11047e265142 | 23 | pc.format(8,SerialBLK::None,1);pc.baud(115200);blue.baud(115200); |
andreashatzl | 0:11047e265142 | 24 | ua0.SvMessage("ServoTest"); |
andreashatzl | 0:11047e265142 | 25 | |
andreashatzl | 0:11047e265142 | 26 | Timer stw; stw.start(); |
andreashatzl | 0:11047e265142 | 27 | while(1) |
andreashatzl | 0:11047e265142 | 28 | { |
andreashatzl | 0:11047e265142 | 29 | CommandHandler(); |
andreashatzl | 0:11047e265142 | 30 | if((stw.read_ms()>100)) |
andreashatzl | 0:11047e265142 | 31 | { |
andreashatzl | 0:11047e265142 | 32 | stw.reset(); |
andreashatzl | 0:11047e265142 | 33 | if(ua0.acqON) |
andreashatzl | 0:11047e265142 | 34 | { |
andreashatzl | 0:11047e265142 | 35 | ua0.SvMessage(stickVal1); |
andreashatzl | 0:11047e265142 | 36 | ua0.WriteSvI16(1, stickVal1); |
andreashatzl | 0:11047e265142 | 37 | ua0.WriteSvI16(2, stickVal2); |
andreashatzl | 0:11047e265142 | 38 | ua0.WriteSvI16(3, stickVal3); |
andreashatzl | 0:11047e265142 | 39 | } |
andreashatzl | 0:11047e265142 | 40 | } |
andreashatzl | 0:11047e265142 | 41 | } |
andreashatzl | 0:11047e265142 | 42 | |
andreashatzl | 0:11047e265142 | 43 | return 1; |
andreashatzl | 0:11047e265142 | 44 | } |
andreashatzl | 0:11047e265142 | 45 | |
andreashatzl | 0:11047e265142 | 46 | |
andreashatzl | 0:11047e265142 | 47 | void CommandHandler() |
andreashatzl | 0:11047e265142 | 48 | { |
andreashatzl | 0:11047e265142 | 49 | uint8_t cmd; |
andreashatzl | 0:11047e265142 | 50 | |
andreashatzl | 0:11047e265142 | 51 | |
andreashatzl | 0:11047e265142 | 52 | // Fragen ob überhaupt etwas im RX-Reg steht |
andreashatzl | 0:11047e265142 | 53 | if( !blue.IsDataAvail() ) |
andreashatzl | 0:11047e265142 | 54 | return; |
andreashatzl | 0:11047e265142 | 55 | |
andreashatzl | 0:11047e265142 | 56 | // wenn etwas im RX-Reg steht |
andreashatzl | 0:11047e265142 | 57 | // Kommando lesen |
andreashatzl | 0:11047e265142 | 58 | cmd = ua0.GetCommand(); |
andreashatzl | 0:11047e265142 | 59 | |
andreashatzl | 0:11047e265142 | 60 | if( cmd==2 ) { |
andreashatzl | 0:11047e265142 | 61 | // cmd2 hat 2 int16 Parameter |
andreashatzl | 0:11047e265142 | 62 | stickVal1 = ua0.ReadI16(); |
andreashatzl | 0:11047e265142 | 63 | servo1.pulsewidth_us(1000+stickVal1); |
andreashatzl | 0:11047e265142 | 64 | } |
andreashatzl | 0:11047e265142 | 65 | if( cmd==3 ) { |
andreashatzl | 0:11047e265142 | 66 | // cmd2 hat 2 int16 Parameter |
andreashatzl | 0:11047e265142 | 67 | stickVal2 = ua0.ReadI16(); |
andreashatzl | 0:11047e265142 | 68 | servo2.pulsewidth_us(1000+stickVal2); |
andreashatzl | 0:11047e265142 | 69 | } |
andreashatzl | 0:11047e265142 | 70 | if( cmd==4 ) { |
andreashatzl | 0:11047e265142 | 71 | // cmd2 hat 2 int16 Parameter |
andreashatzl | 0:11047e265142 | 72 | stickVal3 = ua0.ReadI16(); |
andreashatzl | 0:11047e265142 | 73 | servo3.pulsewidth_us(1000+stickVal3); |
andreashatzl | 0:11047e265142 | 74 | } |
andreashatzl | 0:11047e265142 | 75 | } |