This is a White Wizard Board TANK for Android APP. See these web site: http://app.prtissimo.com/ad/ww_t00/en/ and http://wizard.nestegg.jp/android_tank.html

Dependencies:   mbed

Committer:
halfpitch
Date:
Mon Aug 01 16:05:15 2011 +0000
Revision:
0:06c4875f8acd
Rev.A

Who changed what in which revision?

UserRevisionLine numberNew contents of line
halfpitch 0:06c4875f8acd 1 /*-----------------------------------------
halfpitch 0:06c4875f8acd 2 Nest Egg Inc.
halfpitch 0:06c4875f8acd 3 White Wizard Board Android TANK Ver1.0
halfpitch 0:06c4875f8acd 4
halfpitch 0:06c4875f8acd 5 How to connect?
halfpitch 0:06c4875f8acd 6
halfpitch 0:06c4875f8acd 7 *Bluetooth module
halfpitch 0:06c4875f8acd 8 from p9 to p16.
halfpitch 0:06c4875f8acd 9 (you can select other serial pins)
halfpitch 0:06c4875f8acd 10
halfpitch 0:06c4875f8acd 11 *Motor Driver Board
halfpitch 0:06c4875f8acd 12 p21 - IN_R1
halfpitch 0:06c4875f8acd 13 p22 - IN_R2
halfpitch 0:06c4875f8acd 14 p23 - IN_L2
halfpitch 0:06c4875f8acd 15 p24 - IN_L1
halfpitch 0:06c4875f8acd 16
halfpitch 0:06c4875f8acd 17 -----------------------------------------*/
halfpitch 0:06c4875f8acd 18
halfpitch 0:06c4875f8acd 19 #include "mbed.h"
halfpitch 0:06c4875f8acd 20
halfpitch 0:06c4875f8acd 21 Serial rn42(p9,p10);
halfpitch 0:06c4875f8acd 22 DigitalOut myled(LED1);
halfpitch 0:06c4875f8acd 23 DigitalOut myled2(LED2);
halfpitch 0:06c4875f8acd 24 DigitalOut myled3(LED3);
halfpitch 0:06c4875f8acd 25 DigitalOut myled4(LED4);
halfpitch 0:06c4875f8acd 26
halfpitch 0:06c4875f8acd 27 PwmOut motorR1(p21);
halfpitch 0:06c4875f8acd 28 PwmOut motorR2(p22);
halfpitch 0:06c4875f8acd 29 PwmOut motorL2(p23);
halfpitch 0:06c4875f8acd 30 PwmOut motorL1(p24);
halfpitch 0:06c4875f8acd 31
halfpitch 0:06c4875f8acd 32 void read_string(char*);
halfpitch 0:06c4875f8acd 33
halfpitch 0:06c4875f8acd 34 int main() {
halfpitch 0:06c4875f8acd 35 int i = 0;
halfpitch 0:06c4875f8acd 36 int j = 0;
halfpitch 0:06c4875f8acd 37 char input[255];
halfpitch 0:06c4875f8acd 38 rn42.baud(115200);
halfpitch 0:06c4875f8acd 39
halfpitch 0:06c4875f8acd 40 motorR1.period(0.003*9);
halfpitch 0:06c4875f8acd 41 motorR2.period(0.003*9);
halfpitch 0:06c4875f8acd 42 motorL2.period(0.003*9);
halfpitch 0:06c4875f8acd 43 motorL1.period(0.003*9);
halfpitch 0:06c4875f8acd 44
halfpitch 0:06c4875f8acd 45 float flg_width_a = 0.0;
halfpitch 0:06c4875f8acd 46 float flg_width_b = 0.0;
halfpitch 0:06c4875f8acd 47
halfpitch 0:06c4875f8acd 48 int flg_error;
halfpitch 0:06c4875f8acd 49
halfpitch 0:06c4875f8acd 50 while (1) {
halfpitch 0:06c4875f8acd 51
halfpitch 0:06c4875f8acd 52 i=0;
halfpitch 0:06c4875f8acd 53 flg_error = 0;
halfpitch 0:06c4875f8acd 54 myled2 = 1;
halfpitch 0:06c4875f8acd 55
halfpitch 0:06c4875f8acd 56 if (rn42.readable()) {
halfpitch 0:06c4875f8acd 57
halfpitch 0:06c4875f8acd 58 while ((i==0) || ( input[i-1] != 'G')) {
halfpitch 0:06c4875f8acd 59 input[i] = rn42.getc();
halfpitch 0:06c4875f8acd 60 //printf("%c;%d\n",input[i],i);
halfpitch 0:06c4875f8acd 61 ++i;
halfpitch 0:06c4875f8acd 62 myled != myled;
halfpitch 0:06c4875f8acd 63 }
halfpitch 0:06c4875f8acd 64
halfpitch 0:06c4875f8acd 65 for(j=0;j<i;++j){
halfpitch 0:06c4875f8acd 66 rn42.putc(input[j]);
halfpitch 0:06c4875f8acd 67 }
halfpitch 0:06c4875f8acd 68
halfpitch 0:06c4875f8acd 69 //check format L**R**G
halfpitch 0:06c4875f8acd 70 if((input[0]=='L') && (input[3]=='R') && (input[6]=='G')){
halfpitch 0:06c4875f8acd 71 myled2 = 0;
halfpitch 0:06c4875f8acd 72
halfpitch 0:06c4875f8acd 73 //check speed
halfpitch 0:06c4875f8acd 74 switch(input[2]){
halfpitch 0:06c4875f8acd 75 case '0':
halfpitch 0:06c4875f8acd 76 flg_width_a = 0.0;
halfpitch 0:06c4875f8acd 77 break;
halfpitch 0:06c4875f8acd 78 case '1':
halfpitch 0:06c4875f8acd 79 flg_width_a = 0.003;
halfpitch 0:06c4875f8acd 80 break;
halfpitch 0:06c4875f8acd 81 case '2':
halfpitch 0:06c4875f8acd 82 flg_width_a = 0.003*2;
halfpitch 0:06c4875f8acd 83 break;
halfpitch 0:06c4875f8acd 84 case '3':
halfpitch 0:06c4875f8acd 85 flg_width_a = 0.003*3;
halfpitch 0:06c4875f8acd 86 break;
halfpitch 0:06c4875f8acd 87 case '4':
halfpitch 0:06c4875f8acd 88 flg_width_a = 0.003*4;
halfpitch 0:06c4875f8acd 89 break;
halfpitch 0:06c4875f8acd 90 case '5':
halfpitch 0:06c4875f8acd 91 flg_width_a = 0.003*5;
halfpitch 0:06c4875f8acd 92 break;
halfpitch 0:06c4875f8acd 93 case '6':
halfpitch 0:06c4875f8acd 94 flg_width_a = 0.003*6;
halfpitch 0:06c4875f8acd 95 break;
halfpitch 0:06c4875f8acd 96 case '7':
halfpitch 0:06c4875f8acd 97 flg_width_a = 0.003*7;
halfpitch 0:06c4875f8acd 98 break;
halfpitch 0:06c4875f8acd 99 case '8':
halfpitch 0:06c4875f8acd 100 flg_width_a = 0.003*8;
halfpitch 0:06c4875f8acd 101 break;
halfpitch 0:06c4875f8acd 102 case '9':
halfpitch 0:06c4875f8acd 103 flg_width_a = 0.003*9;
halfpitch 0:06c4875f8acd 104 break;
halfpitch 0:06c4875f8acd 105 default:
halfpitch 0:06c4875f8acd 106 flg_error = 1;
halfpitch 0:06c4875f8acd 107
halfpitch 0:06c4875f8acd 108 }
halfpitch 0:06c4875f8acd 109
halfpitch 0:06c4875f8acd 110
halfpitch 0:06c4875f8acd 111 switch(input[1]){
halfpitch 0:06c4875f8acd 112 case 'F':
halfpitch 0:06c4875f8acd 113 motorL2.pulsewidth(flg_width_a);
halfpitch 0:06c4875f8acd 114 motorL1.pulsewidth(0);
halfpitch 0:06c4875f8acd 115 break;
halfpitch 0:06c4875f8acd 116 case 'B':
halfpitch 0:06c4875f8acd 117 motorL2.pulsewidth(0);
halfpitch 0:06c4875f8acd 118 motorL1.pulsewidth(flg_width_a);
halfpitch 0:06c4875f8acd 119 break;
halfpitch 0:06c4875f8acd 120 default:
halfpitch 0:06c4875f8acd 121 flg_error = 1;
halfpitch 0:06c4875f8acd 122
halfpitch 0:06c4875f8acd 123 }
halfpitch 0:06c4875f8acd 124
halfpitch 0:06c4875f8acd 125 //check speed
halfpitch 0:06c4875f8acd 126 switch(input[5]){
halfpitch 0:06c4875f8acd 127 case '0':
halfpitch 0:06c4875f8acd 128 flg_width_b = 0.0;
halfpitch 0:06c4875f8acd 129 break;
halfpitch 0:06c4875f8acd 130 case '1':
halfpitch 0:06c4875f8acd 131 flg_width_b = 0.003;
halfpitch 0:06c4875f8acd 132 break;
halfpitch 0:06c4875f8acd 133 case '2':
halfpitch 0:06c4875f8acd 134 flg_width_b = 0.003*2;
halfpitch 0:06c4875f8acd 135 break;
halfpitch 0:06c4875f8acd 136 case '3':
halfpitch 0:06c4875f8acd 137 flg_width_b = 0.003*3;
halfpitch 0:06c4875f8acd 138 break;
halfpitch 0:06c4875f8acd 139 case '4':
halfpitch 0:06c4875f8acd 140 flg_width_b = 0.003*4;
halfpitch 0:06c4875f8acd 141 break;
halfpitch 0:06c4875f8acd 142 case '5':
halfpitch 0:06c4875f8acd 143 flg_width_b = 0.003*5;
halfpitch 0:06c4875f8acd 144 break;
halfpitch 0:06c4875f8acd 145 case '6':
halfpitch 0:06c4875f8acd 146 flg_width_b = 0.003*6;
halfpitch 0:06c4875f8acd 147 break;
halfpitch 0:06c4875f8acd 148 case '7':
halfpitch 0:06c4875f8acd 149 flg_width_b = 0.003*7;
halfpitch 0:06c4875f8acd 150 break;
halfpitch 0:06c4875f8acd 151 case '8':
halfpitch 0:06c4875f8acd 152 flg_width_b = 0.003*8;
halfpitch 0:06c4875f8acd 153 break;
halfpitch 0:06c4875f8acd 154 case '9':
halfpitch 0:06c4875f8acd 155 flg_width_b = 0.003*9;
halfpitch 0:06c4875f8acd 156 break;
halfpitch 0:06c4875f8acd 157 default:
halfpitch 0:06c4875f8acd 158 flg_error = 1;
halfpitch 0:06c4875f8acd 159
halfpitch 0:06c4875f8acd 160 }
halfpitch 0:06c4875f8acd 161
halfpitch 0:06c4875f8acd 162 switch(input[4]){
halfpitch 0:06c4875f8acd 163
halfpitch 0:06c4875f8acd 164 case 'F':
halfpitch 0:06c4875f8acd 165 motorR2.pulsewidth(flg_width_b);
halfpitch 0:06c4875f8acd 166 motorR1.pulsewidth(0);
halfpitch 0:06c4875f8acd 167 myled3 = 0;
halfpitch 0:06c4875f8acd 168 break;
halfpitch 0:06c4875f8acd 169 case 'B':
halfpitch 0:06c4875f8acd 170 motorR2.pulsewidth(0);
halfpitch 0:06c4875f8acd 171 motorR1.pulsewidth(flg_width_b);
halfpitch 0:06c4875f8acd 172 myled3 = 0;
halfpitch 0:06c4875f8acd 173 break;
halfpitch 0:06c4875f8acd 174 default:
halfpitch 0:06c4875f8acd 175 flg_error = 1;
halfpitch 0:06c4875f8acd 176
halfpitch 0:06c4875f8acd 177 }
halfpitch 0:06c4875f8acd 178 }
halfpitch 0:06c4875f8acd 179 }
halfpitch 0:06c4875f8acd 180
halfpitch 0:06c4875f8acd 181 if(flg_error == 1){
halfpitch 0:06c4875f8acd 182 myled2 = 1;
halfpitch 0:06c4875f8acd 183 motorL2.pulsewidth(0);
halfpitch 0:06c4875f8acd 184 motorL1.pulsewidth(0);
halfpitch 0:06c4875f8acd 185 motorR2.pulsewidth(0);
halfpitch 0:06c4875f8acd 186 motorR1.pulsewidth(0);
halfpitch 0:06c4875f8acd 187
halfpitch 0:06c4875f8acd 188 }
halfpitch 0:06c4875f8acd 189 //wait(0.05);
halfpitch 0:06c4875f8acd 190
halfpitch 0:06c4875f8acd 191 }
halfpitch 0:06c4875f8acd 192 }