This is Compact Conoroller program using "FEP" library.

Dependencies:   FEP mbed

Committer:
eil4nyqn
Date:
Sat Jul 22 06:22:48 2017 +0000
Revision:
3:86eed23d1883
Parent:
2:cb00e9fed324
updated FEP library, not checked operation

Who changed what in which revision?

UserRevisionLine numberNew 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 3:86eed23d1883 7 FEP fep(PA_2,PA_3,000);
eil4nyqn 3:86eed23d1883 8 //FEP fep(PB_10,PB_11,000);
eil4nyqn 0:b7708bb00e0c 9 Serial xbee(PA_9,PA_10,38400);
eil4nyqn 0:b7708bb00e0c 10 Serial pc(PB_10,PB_11,115200);
eil4nyqn 0:b7708bb00e0c 11 DigitalOut leds[4]={PB_15,PB_14,PB_13,PB_12};
eil4nyqn 0:b7708bb00e0c 12
eil4nyqn 0:b7708bb00e0c 13 void LED_allOFF(){
eil4nyqn 0:b7708bb00e0c 14 int i;
eil4nyqn 0:b7708bb00e0c 15 for(i=0;i<4;i++){
eil4nyqn 0:b7708bb00e0c 16 leds[i]=1;
eil4nyqn 0:b7708bb00e0c 17 }
eil4nyqn 0:b7708bb00e0c 18 }
eil4nyqn 0:b7708bb00e0c 19
eil4nyqn 0:b7708bb00e0c 20 void getInputState(double stick_val[],uint8_t SW_val[]){
eil4nyqn 0:b7708bb00e0c 21 int i;
eil4nyqn 0:b7708bb00e0c 22 SW_val[0]=onSW;
eil4nyqn 0:b7708bb00e0c 23 SW_val[1]=otherSW;
eil4nyqn 0:b7708bb00e0c 24 for(i=0;i<4;i++){
eil4nyqn 0:b7708bb00e0c 25 stick_val[i]=Stick[i];
eil4nyqn 0:b7708bb00e0c 26 }
eil4nyqn 0:b7708bb00e0c 27 }
eil4nyqn 0:b7708bb00e0c 28
eil4nyqn 0:b7708bb00e0c 29 void convertTXdata(double stick_val[],uint8_t SW_val[],char TXdata[]){
eil4nyqn 0:b7708bb00e0c 30 int i;
eil4nyqn 0:b7708bb00e0c 31 for(i=0;i<4;i++){
eil4nyqn 0:b7708bb00e0c 32 TXdata[i]=255*stick_val[i];
eil4nyqn 0:b7708bb00e0c 33 }
eil4nyqn 0:b7708bb00e0c 34 TXdata[4]=SW_val[0];
eil4nyqn 0:b7708bb00e0c 35 TXdata[5]=SW_val[1];
eil4nyqn 0:b7708bb00e0c 36 }
eil4nyqn 0:b7708bb00e0c 37
eil4nyqn 0:b7708bb00e0c 38
eil4nyqn 0:b7708bb00e0c 39 int main() {
eil4nyqn 0:b7708bb00e0c 40 onSW.mode(PullUp);
eil4nyqn 0:b7708bb00e0c 41 otherSW.mode(PullUp);
eil4nyqn 0:b7708bb00e0c 42 LED_allOFF();
eil4nyqn 0:b7708bb00e0c 43 double stick_val[4];
eil4nyqn 0:b7708bb00e0c 44 uint8_t SW_val[2];
eil4nyqn 0:b7708bb00e0c 45 char TXdata[128];
eil4nyqn 0:b7708bb00e0c 46 uint8_t FEPstate;
eil4nyqn 0:b7708bb00e0c 47 while(1) {
eil4nyqn 0:b7708bb00e0c 48 getInputState(stick_val,SW_val);
eil4nyqn 0:b7708bb00e0c 49 convertTXdata(stick_val,SW_val,TXdata);
eil4nyqn 3:86eed23d1883 50 FEPstate=fep.puts(TXdata,6);
eil4nyqn 0:b7708bb00e0c 51 leds[3]!=leds[3];
eil4nyqn 0:b7708bb00e0c 52 if(FEPstate==FEP_P0){
eil4nyqn 0:b7708bb00e0c 53 leds[0]=0;
eil4nyqn 0:b7708bb00e0c 54 leds[1]=1;
eil4nyqn 0:b7708bb00e0c 55 leds[2]=1;
eil4nyqn 0:b7708bb00e0c 56 continue;
eil4nyqn 0:b7708bb00e0c 57 }else if(FEPstate==FEP_N0){
eil4nyqn 0:b7708bb00e0c 58 leds[0]=1;
eil4nyqn 0:b7708bb00e0c 59 leds[1]=0;
eil4nyqn 0:b7708bb00e0c 60 leds[2]=1;
eil4nyqn 0:b7708bb00e0c 61 continue;
eil4nyqn 0:b7708bb00e0c 62 }else if(FEPstate==FEP_N1){
eil4nyqn 0:b7708bb00e0c 63 leds[0]=1;
eil4nyqn 0:b7708bb00e0c 64 leds[1]=1;
eil4nyqn 0:b7708bb00e0c 65 leds[2]=0;
eil4nyqn 0:b7708bb00e0c 66 continue;
eil4nyqn 0:b7708bb00e0c 67 }else{
eil4nyqn 0:b7708bb00e0c 68 leds[0]=1;
eil4nyqn 0:b7708bb00e0c 69 leds[1]=1;
eil4nyqn 0:b7708bb00e0c 70 leds[2]=1;
eil4nyqn 0:b7708bb00e0c 71 }
eil4nyqn 0:b7708bb00e0c 72 }
eil4nyqn 0:b7708bb00e0c 73 }