NagaokaRoboticsClub_mbedTeam
/
CompactController_2017
This is Compact Conoroller program using "FEP" library.
main.cpp@2:cb00e9fed324, 2017-07-14 (annotated)
- Committer:
- eil4nyqn
- Date:
- Fri Jul 14 13:25:03 2017 +0000
- Revision:
- 2:cb00e9fed324
- Parent:
- 0:b7708bb00e0c
- Child:
- 3:86eed23d1883
fixed not mach function name of FEP lib
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
eil4nyqn | 0:b7708bb00e0c | 1 | #include "mbed.h" |
eil4nyqn | 0:b7708bb00e0c | 2 | #include "FEP.h" |
eil4nyqn | 0:b7708bb00e0c | 3 | |
eil4nyqn | 0:b7708bb00e0c | 4 | BusIn onSW(PA_4,PA_5,PB_5,PB_4,PB_3,PA_15,PA_12); |
eil4nyqn | 0:b7708bb00e0c | 5 | BusIn otherSW(PC_13,PC_14,PB_9,PC_15,PA_11,PA_1); |
eil4nyqn | 0:b7708bb00e0c | 6 | AnalogIn Stick[4]={PA_6,PA_7,PB_0,PB_1}; |
eil4nyqn | 0:b7708bb00e0c | 7 | FEP fep(PA_2,PA_3); |
eil4nyqn | 0:b7708bb00e0c | 8 | Serial xbee(PA_9,PA_10,38400); |
eil4nyqn | 0:b7708bb00e0c | 9 | Serial pc(PB_10,PB_11,115200); |
eil4nyqn | 0:b7708bb00e0c | 10 | DigitalOut leds[4]={PB_15,PB_14,PB_13,PB_12}; |
eil4nyqn | 0:b7708bb00e0c | 11 | |
eil4nyqn | 0:b7708bb00e0c | 12 | void LED_allOFF(){ |
eil4nyqn | 0:b7708bb00e0c | 13 | int i; |
eil4nyqn | 0:b7708bb00e0c | 14 | for(i=0;i<4;i++){ |
eil4nyqn | 0:b7708bb00e0c | 15 | leds[i]=1; |
eil4nyqn | 0:b7708bb00e0c | 16 | } |
eil4nyqn | 0:b7708bb00e0c | 17 | } |
eil4nyqn | 0:b7708bb00e0c | 18 | |
eil4nyqn | 0:b7708bb00e0c | 19 | void getInputState(double stick_val[],uint8_t SW_val[]){ |
eil4nyqn | 0:b7708bb00e0c | 20 | int i; |
eil4nyqn | 0:b7708bb00e0c | 21 | SW_val[0]=onSW; |
eil4nyqn | 0:b7708bb00e0c | 22 | SW_val[1]=otherSW; |
eil4nyqn | 0:b7708bb00e0c | 23 | for(i=0;i<4;i++){ |
eil4nyqn | 0:b7708bb00e0c | 24 | stick_val[i]=Stick[i]; |
eil4nyqn | 0:b7708bb00e0c | 25 | } |
eil4nyqn | 0:b7708bb00e0c | 26 | } |
eil4nyqn | 0:b7708bb00e0c | 27 | |
eil4nyqn | 0:b7708bb00e0c | 28 | void convertTXdata(double stick_val[],uint8_t SW_val[],char TXdata[]){ |
eil4nyqn | 0:b7708bb00e0c | 29 | int i; |
eil4nyqn | 0:b7708bb00e0c | 30 | for(i=0;i<4;i++){ |
eil4nyqn | 0:b7708bb00e0c | 31 | TXdata[i]=255*stick_val[i]; |
eil4nyqn | 0:b7708bb00e0c | 32 | } |
eil4nyqn | 0:b7708bb00e0c | 33 | TXdata[4]=SW_val[0]; |
eil4nyqn | 0:b7708bb00e0c | 34 | TXdata[5]=SW_val[1]; |
eil4nyqn | 0:b7708bb00e0c | 35 | } |
eil4nyqn | 0:b7708bb00e0c | 36 | |
eil4nyqn | 0:b7708bb00e0c | 37 | |
eil4nyqn | 0:b7708bb00e0c | 38 | int main() { |
eil4nyqn | 0:b7708bb00e0c | 39 | onSW.mode(PullUp); |
eil4nyqn | 0:b7708bb00e0c | 40 | otherSW.mode(PullUp); |
eil4nyqn | 0:b7708bb00e0c | 41 | LED_allOFF(); |
eil4nyqn | 0:b7708bb00e0c | 42 | double stick_val[4]; |
eil4nyqn | 0:b7708bb00e0c | 43 | uint8_t SW_val[2]; |
eil4nyqn | 0:b7708bb00e0c | 44 | char TXdata[128]; |
eil4nyqn | 0:b7708bb00e0c | 45 | //set reciever module address (the last three numbers of S/N) |
eil4nyqn | 0:b7708bb00e0c | 46 | const uint8_t address=198; |
eil4nyqn | 0:b7708bb00e0c | 47 | uint8_t FEPstate; |
eil4nyqn | 0:b7708bb00e0c | 48 | while(1) { |
eil4nyqn | 0:b7708bb00e0c | 49 | getInputState(stick_val,SW_val); |
eil4nyqn | 0:b7708bb00e0c | 50 | convertTXdata(stick_val,SW_val,TXdata); |
eil4nyqn | 2:cb00e9fed324 | 51 | FEPstate=fep.write_txt(TXdata,address,6); |
eil4nyqn | 0:b7708bb00e0c | 52 | leds[3]!=leds[3]; |
eil4nyqn | 0:b7708bb00e0c | 53 | if(FEPstate==FEP_P0){ |
eil4nyqn | 0:b7708bb00e0c | 54 | leds[0]=0; |
eil4nyqn | 0:b7708bb00e0c | 55 | leds[1]=1; |
eil4nyqn | 0:b7708bb00e0c | 56 | leds[2]=1; |
eil4nyqn | 0:b7708bb00e0c | 57 | continue; |
eil4nyqn | 0:b7708bb00e0c | 58 | }else if(FEPstate==FEP_N0){ |
eil4nyqn | 0:b7708bb00e0c | 59 | leds[0]=1; |
eil4nyqn | 0:b7708bb00e0c | 60 | leds[1]=0; |
eil4nyqn | 0:b7708bb00e0c | 61 | leds[2]=1; |
eil4nyqn | 0:b7708bb00e0c | 62 | continue; |
eil4nyqn | 0:b7708bb00e0c | 63 | }else if(FEPstate==FEP_N1){ |
eil4nyqn | 0:b7708bb00e0c | 64 | leds[0]=1; |
eil4nyqn | 0:b7708bb00e0c | 65 | leds[1]=1; |
eil4nyqn | 0:b7708bb00e0c | 66 | leds[2]=0; |
eil4nyqn | 0:b7708bb00e0c | 67 | continue; |
eil4nyqn | 0:b7708bb00e0c | 68 | }else{ |
eil4nyqn | 0:b7708bb00e0c | 69 | leds[0]=1; |
eil4nyqn | 0:b7708bb00e0c | 70 | leds[1]=1; |
eil4nyqn | 0:b7708bb00e0c | 71 | leds[2]=1; |
eil4nyqn | 0:b7708bb00e0c | 72 | wait(0.1); |
eil4nyqn | 0:b7708bb00e0c | 73 | } |
eil4nyqn | 0:b7708bb00e0c | 74 | } |
eil4nyqn | 0:b7708bb00e0c | 75 | } |