Dependencies:   TextLCD mbed

Fork of Mbed-Mensch-1 by Projekte_werkstatt

Committer:
ladner
Date:
Fri Mar 11 07:47:58 2016 +0000
Revision:
5:f4db4cd245e3
Parent:
4:2acb70f9cd22
Child:
6:eda2b36d5be1

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ladner 0:e97a6a69fe4b 1 #include "mbed.h"
ladner 1:0eaa7682f7e1 2 #include "WS2812B.h"
ladner 5:f4db4cd245e3 3 #include "TextLCD.h"
ladner 5:f4db4cd245e3 4 #include <string>
ladner 0:e97a6a69fe4b 5
ladner 0:e97a6a69fe4b 6 I2C i2c(P0_5,P0_4);
ladner 0:e97a6a69fe4b 7 Serial port(P0_19,P0_18);
ladner 0:e97a6a69fe4b 8 BusOut myled(P1_8,P1_9,P1_10,P1_11,P1_0,P1_1,P1_3,P1_4,P1_6,P1_7,P1_12,P1_13);
ladner 0:e97a6a69fe4b 9 AnalogIn ldr(P0_12);
ladner 0:e97a6a69fe4b 10 AnalogIn poti(P0_11);
ladner 1:0eaa7682f7e1 11 //BusOut rgb(P0_9,P1_15,P0_21);
ladner 1:0eaa7682f7e1 12 //BusIn btn(P1_16,P0_23,P0_10,P0_15);
ladner 1:0eaa7682f7e1 13
ladner 1:0eaa7682f7e1 14 RGBOut rgb(P0_21,P0_9,P1_15);
ladner 5:f4db4cd245e3 15 TextLCD lcd(p21, p22, p26, p25, p24, p23,TextLCD::LCD20x4);
ladner 1:0eaa7682f7e1 16
ladner 1:0eaa7682f7e1 17 LedOut Feld (P0_13);
ladner 1:0eaa7682f7e1 18 //LedOut Other(P0_13); //-> Würfel (ersten 3 LED in Binär-4. LED für 7. Zustand), Spieler, Start, Ziel, Referenz(auch RGB am board)
ladner 1:0eaa7682f7e1 19 // übrige 8 LED für zeit-Anzeige des Zuges einer KI
ladner 1:0eaa7682f7e1 20
ladner 1:0eaa7682f7e1 21 InterruptIn Button0(P0_1);
ladner 0:e97a6a69fe4b 22 InterruptIn Button1(P1_16);
ladner 0:e97a6a69fe4b 23 InterruptIn Button2(P0_23);
ladner 1:0eaa7682f7e1 24 InterruptIn Button3(P0_10);
ladner 1:0eaa7682f7e1 25 InterruptIn Button4(P0_15);
ladner 0:e97a6a69fe4b 26
ladner 5:f4db4cd245e3 27 InterruptIn DD_A(P0_22);//20
ladner 5:f4db4cd245e3 28 InterruptIn DD_B(P0_16);//19
ladner 5:f4db4cd245e3 29 InterruptIn DD_C(P0_14);//18
ladner 5:f4db4cd245e3 30 DigitalIn DD_D(P0_14);
ladner 5:f4db4cd245e3 31 BusIn DD(P0_22,P0_16);
ladner 5:f4db4cd245e3 32 //Timeout DD_reset;
ladner 5:f4db4cd245e3 33 char DD_last;
ladner 5:f4db4cd245e3 34 char DD_d;
ladner 1:0eaa7682f7e1 35
ladner 5:f4db4cd245e3 36 void dreh();
ladner 5:f4db4cd245e3 37 void druck();
ladner 1:0eaa7682f7e1 38
ladner 5:f4db4cd245e3 39 void up();
ladner 5:f4db4cd245e3 40 void down();
ladner 5:f4db4cd245e3 41 void accept();
ladner 5:f4db4cd245e3 42 void exit();
ladner 5:f4db4cd245e3 43 void print_menu();
ladner 5:f4db4cd245e3 44 void Control();
ladner 1:0eaa7682f7e1 45
ladner 5:f4db4cd245e3 46 //string test ("");
ladner 5:f4db4cd245e3 47 // "1234567890123456789","1234567890123456789","1234567890123456789","1234567890123456789", ,"1234567890123456789","1234567890123456789","1234567890123456789",
ladner 5:f4db4cd245e3 48 const char * const text_ln0[] = {"MENU: ","Spiel-Menu: ","Anzeige-Menu: ","Speicher-Menu: ","","7.Zustand-Menu: ","Farben-Menu: ","Spiel-Menu: ","","Spielregeln-Menu: ","Hell./Sp.Led-Menu: ","Config-Menu: ","","Autplay-Menu: ","Wurfel-Menu: ","Ofline/Com-Menu: "};
ladner 5:f4db4cd245e3 49 const char * const text_ln1[] = {"Spiel ","7.Zustand ","Farben ","Spiel ","","Disable "," ","Laden ","","Smeiszwang <I/0> ","Wert: <wert> ","Laden ","","Zeit ","Farbverhalten ","New "};
ladner 5:f4db4cd245e3 50 const char * const text_ln2[] = {"Anzeige ","Spielregeln ","Hellichkeit/Sp.Led ","Config. ","","kleinstmoglich ","SP: 1 2 3 4 ","Speichern ","","Go Home first <I/0>","Sp.Led-Verhalten ","Speichern ","","Agro/Taktik ","Farb def ","Reset "};
ladner 5:f4db4cd245e3 51 const char * const text_ln3[] = {"Speicher ","Autoplay ","Wurfel ","Ofline/Com ","","grostmoglich "," ","Reset ","","Ausfahrzwang <I/0> ","Andert: <wert> ","Reset ","","Enable/Manuell ","Hellichkeit ","Com "};
ladner 1:0eaa7682f7e1 52
ladner 5:f4db4cd245e3 53
ladner 5:f4db4cd245e3 54 char selected[256];
ladner 5:f4db4cd245e3 55 char depth = 0;
ladner 0:e97a6a69fe4b 56
ladner 1:0eaa7682f7e1 57 int main()
ladner 0:e97a6a69fe4b 58 {
ladner 5:f4db4cd245e3 59 //Random.start();
ladner 1:0eaa7682f7e1 60 //Random.stop();
ladner 1:0eaa7682f7e1 61 //Random.read_us();
ladner 1:0eaa7682f7e1 62
ladner 1:0eaa7682f7e1 63 //Ticker:
ladner 1:0eaa7682f7e1 64 //.attach(&main,[sek]);
ladner 1:0eaa7682f7e1 65 //.attach_us(&main,[micro-sec]);
ladner 1:0eaa7682f7e1 66 //.detach();
ladner 1:0eaa7682f7e1 67
ladner 1:0eaa7682f7e1 68 //myled = 0xFFF;
ladner 1:0eaa7682f7e1 69 port.baud(76800);
ladner 1:0eaa7682f7e1 70 port.format(8,Serial::None, 1);
ladner 1:0eaa7682f7e1 71 port.attach(&Control);
ladner 4:2acb70f9cd22 72 /*
ladner 5:f4db4cd245e3 73 __disable_irq();
ladner 5:f4db4cd245e3 74 __enable_irq();
ladner 4:2acb70f9cd22 75 */
ladner 5:f4db4cd245e3 76 wait(0.01);
ladner 5:f4db4cd245e3 77 DD_A.mode(PullDown);
ladner 5:f4db4cd245e3 78 DD_B.mode(PullDown);
ladner 5:f4db4cd245e3 79 DD_C.mode(PullDown);
ladner 5:f4db4cd245e3 80 DD_A.rise(&dreh);
ladner 5:f4db4cd245e3 81 DD_A.fall(&dreh);
ladner 5:f4db4cd245e3 82 DD_B.rise(&dreh);
ladner 5:f4db4cd245e3 83 DD_B.fall(&dreh);
ladner 5:f4db4cd245e3 84 DD_C.rise(&druck);
ladner 5:f4db4cd245e3 85 DD_C.fall(&druck);
ladner 5:f4db4cd245e3 86 DD_last = DD;
ladner 5:f4db4cd245e3 87 DD_d=DD_D;
ladner 1:0eaa7682f7e1 88
ladner 5:f4db4cd245e3 89 //text_ln0[0]="";
ladner 5:f4db4cd245e3 90 //port.printf("D%c%ctest\n",27,27);
ladner 5:f4db4cd245e3 91 print_menu();
ladner 1:0eaa7682f7e1 92
ladner 1:0eaa7682f7e1 93 while(1) ;
ladner 0:e97a6a69fe4b 94 }
ladner 5:f4db4cd245e3 95 void Control()
ladner 1:0eaa7682f7e1 96 {
ladner 5:f4db4cd245e3 97 while(port.readable ())
ladner 1:0eaa7682f7e1 98 {
ladner 5:f4db4cd245e3 99 char message = port.getc();
ladner 5:f4db4cd245e3 100 switch(message)
ladner 1:0eaa7682f7e1 101 {
ladner 5:f4db4cd245e3 102 case 'D':
ladner 5:f4db4cd245e3 103 port.printf("Ldepth:%d,selected[depth-1]:%d\n",depth,selected[depth-1]);
ladner 5:f4db4cd245e3 104 break;
ladner 5:f4db4cd245e3 105 case 'E':
ladner 5:f4db4cd245e3 106 exit();
ladner 5:f4db4cd245e3 107 break;
ladner 5:f4db4cd245e3 108 case 'F':
ladner 5:f4db4cd245e3 109 up();
ladner 5:f4db4cd245e3 110 break;
ladner 5:f4db4cd245e3 111 case 'G':
ladner 5:f4db4cd245e3 112 down();
ladner 5:f4db4cd245e3 113 break;
ladner 5:f4db4cd245e3 114 case 'H':
ladner 5:f4db4cd245e3 115 accept();
ladner 5:f4db4cd245e3 116 break;
ladner 5:f4db4cd245e3 117 case 'I':
ladner 5:f4db4cd245e3 118 depth=0;
ladner 5:f4db4cd245e3 119 selected[0]=0;
ladner 5:f4db4cd245e3 120 print_menu();
ladner 5:f4db4cd245e3 121 break;
ladner 1:0eaa7682f7e1 122 }
ladner 1:0eaa7682f7e1 123 }
ladner 1:0eaa7682f7e1 124 }
ladner 5:f4db4cd245e3 125 void dreh()
ladner 1:0eaa7682f7e1 126 {
ladner 5:f4db4cd245e3 127 char temp = DD;
ladner 5:f4db4cd245e3 128 if(DD_last == 3)
ladner 5:f4db4cd245e3 129 {
ladner 5:f4db4cd245e3 130 if(temp == 0)
ladner 5:f4db4cd245e3 131 DD_last = 0;
ladner 5:f4db4cd245e3 132 }
ladner 1:0eaa7682f7e1 133 else
ladner 1:0eaa7682f7e1 134 {
ladner 5:f4db4cd245e3 135 if(temp == 3)
ladner 5:f4db4cd245e3 136 {
ladner 5:f4db4cd245e3 137 if(DD_last == 1)
ladner 5:f4db4cd245e3 138 up();
ladner 5:f4db4cd245e3 139 if(DD_last == 2)
ladner 5:f4db4cd245e3 140 down();
ladner 5:f4db4cd245e3 141 }
ladner 5:f4db4cd245e3 142 DD_last = temp;
ladner 1:0eaa7682f7e1 143 }
ladner 0:e97a6a69fe4b 144 }
ladner 1:0eaa7682f7e1 145
ladner 5:f4db4cd245e3 146 void druck()
ladner 1:0eaa7682f7e1 147 {
ladner 5:f4db4cd245e3 148 if(DD_D==DD_d)
ladner 5:f4db4cd245e3 149 return;
ladner 5:f4db4cd245e3 150 else if(DD_D)
ladner 5:f4db4cd245e3 151 accept();
ladner 5:f4db4cd245e3 152 DD_d=DD_D;
ladner 0:e97a6a69fe4b 153 }
ladner 1:0eaa7682f7e1 154
ladner 5:f4db4cd245e3 155 void up()
ladner 0:e97a6a69fe4b 156 {
ladner 5:f4db4cd245e3 157 if(depth>0)
ladner 0:e97a6a69fe4b 158 {
ladner 5:f4db4cd245e3 159 if(selected[depth-1]<1)
ladner 5:f4db4cd245e3 160 selected[depth-1]=3;
ladner 5:f4db4cd245e3 161 else
ladner 5:f4db4cd245e3 162 selected[depth-1]--;
ladner 1:0eaa7682f7e1 163 }
ladner 5:f4db4cd245e3 164 print_menu();
ladner 1:0eaa7682f7e1 165 }
ladner 5:f4db4cd245e3 166 void down()
ladner 1:0eaa7682f7e1 167 {
ladner 5:f4db4cd245e3 168 if(depth>0)
ladner 1:0eaa7682f7e1 169 {
ladner 5:f4db4cd245e3 170 if(selected[depth-1]>2)
ladner 5:f4db4cd245e3 171 selected[depth-1]=0;
ladner 1:0eaa7682f7e1 172 else
ladner 5:f4db4cd245e3 173 selected[depth-1]++;
ladner 1:0eaa7682f7e1 174 }
ladner 5:f4db4cd245e3 175 print_menu();
ladner 5:f4db4cd245e3 176 }
ladner 5:f4db4cd245e3 177 void accept()
ladner 5:f4db4cd245e3 178 {
ladner 5:f4db4cd245e3 179 if(depth>0)
ladner 2:3a90b20958ff 180 {
ladner 5:f4db4cd245e3 181 if(depth<=3)
ladner 2:3a90b20958ff 182 {
ladner 5:f4db4cd245e3 183 if(selected[depth-1]==0)
ladner 5:f4db4cd245e3 184 exit();
ladner 5:f4db4cd245e3 185 else
ladner 2:3a90b20958ff 186 {
ladner 5:f4db4cd245e3 187 selected[depth]=1;
ladner 5:f4db4cd245e3 188 depth++;
ladner 2:3a90b20958ff 189 }
ladner 2:3a90b20958ff 190 }
ladner 0:e97a6a69fe4b 191 }
ladner 5:f4db4cd245e3 192 else
ladner 5:f4db4cd245e3 193 depth=1;
ladner 5:f4db4cd245e3 194 print_menu();
ladner 5:f4db4cd245e3 195 }
ladner 5:f4db4cd245e3 196 void exit()
ladner 5:f4db4cd245e3 197 {
ladner 5:f4db4cd245e3 198 if(depth>0)
ladner 0:e97a6a69fe4b 199 {
ladner 5:f4db4cd245e3 200 depth--;
ladner 5:f4db4cd245e3 201 if(depth<=3)
ladner 5:f4db4cd245e3 202 selected[depth]=0;
ladner 2:3a90b20958ff 203 }
ladner 5:f4db4cd245e3 204 print_menu();
ladner 5:f4db4cd245e3 205 }
ladner 5:f4db4cd245e3 206 void print_menu()
ladner 5:f4db4cd245e3 207 {
ladner 5:f4db4cd245e3 208 if(depth>0)
ladner 2:3a90b20958ff 209 {
ladner 5:f4db4cd245e3 210 if(depth>3)// " "
ladner 5:f4db4cd245e3 211 {
ladner 5:f4db4cd245e3 212 port.printf("D%c%c Custom \n",27,27);
ladner 5:f4db4cd245e3 213 lcd.locate(0,0);
ladner 5:f4db4cd245e3 214 lcd.printf(" Custom ");
ladner 5:f4db4cd245e3 215 }
ladner 5:f4db4cd245e3 216 else
ladner 0:e97a6a69fe4b 217 {
ladner 5:f4db4cd245e3 218 uint32_t _selected = 0;
ladner 5:f4db4cd245e3 219 for(char i = 0;i<depth-1;i++)
ladner 5:f4db4cd245e3 220 _selected = _selected|(selected[i]<<(i*2));
ladner 5:f4db4cd245e3 221 //port.printf("L_selected:%d\n",_selected);
ladner 5:f4db4cd245e3 222 lcd.locate(1,0);
ladner 5:f4db4cd245e3 223 lcd.printf(text_ln0[_selected]);
ladner 5:f4db4cd245e3 224 port.printf("D%c%c%s\n",28,27,text_ln0[_selected]);
ladner 5:f4db4cd245e3 225 lcd.locate(1,1);
ladner 5:f4db4cd245e3 226 lcd.printf(text_ln1[_selected]);
ladner 5:f4db4cd245e3 227 port.printf("D%c%c%s\n",28,28,text_ln1[_selected]);
ladner 5:f4db4cd245e3 228 lcd.locate(1,2);
ladner 5:f4db4cd245e3 229 lcd.printf(text_ln2[_selected]);
ladner 5:f4db4cd245e3 230 port.printf("D%c%c%s\n",28,29,text_ln2[_selected]);
ladner 5:f4db4cd245e3 231 lcd.locate(1,3);
ladner 5:f4db4cd245e3 232 lcd.printf(text_ln3[_selected]);
ladner 5:f4db4cd245e3 233 port.printf("D%c%c%s\n",28,30,text_ln3[_selected]);
ladner 5:f4db4cd245e3 234
ladner 5:f4db4cd245e3 235 for(char i=0;i<4;i++)
ladner 1:0eaa7682f7e1 236 {
ladner 5:f4db4cd245e3 237 lcd.locate(0,i);
ladner 5:f4db4cd245e3 238 if((selected[depth-1]+0)==i)
ladner 1:0eaa7682f7e1 239 {
ladner 5:f4db4cd245e3 240 if(i==0)
ladner 1:0eaa7682f7e1 241 {
ladner 5:f4db4cd245e3 242 port.printf("D%c%c<\n",27,i+27);
ladner 5:f4db4cd245e3 243 lcd.putc('<');
ladner 1:0eaa7682f7e1 244 }
ladner 5:f4db4cd245e3 245 else
ladner 5:f4db4cd245e3 246 {
ladner 5:f4db4cd245e3 247 port.printf("D%c%c>\n",27,i+27);
ladner 5:f4db4cd245e3 248 lcd.putc('>');
ladner 5:f4db4cd245e3 249 }
ladner 1:0eaa7682f7e1 250 }
ladner 2:3a90b20958ff 251 else
ladner 5:f4db4cd245e3 252 {
ladner 5:f4db4cd245e3 253 port.printf("D%c%c \n",27,i+27);
ladner 5:f4db4cd245e3 254 lcd.putc(' ');
ladner 2:3a90b20958ff 255 }
ladner 1:0eaa7682f7e1 256 }
ladner 1:0eaa7682f7e1 257 }
ladner 1:0eaa7682f7e1 258 }
ladner 1:0eaa7682f7e1 259 else
ladner 1:0eaa7682f7e1 260 {
ladner 5:f4db4cd245e3 261 lcd.cls();
ladner 5:f4db4cd245e3 262 lcd.printf(" Spiel lauft...");
ladner 5:f4db4cd245e3 263 lcd.locate(0,3);
ladner 5:f4db4cd245e3 264 lcd.printf("12345678901234567890");
ladner 5:f4db4cd245e3 265 port.printf("D%c%c Spiel lauft... \n",27,27);
ladner 5:f4db4cd245e3 266 port.printf("D%c%c \n",27,28);
ladner 5:f4db4cd245e3 267 port.printf("D%c%c \n",27,29);
ladner 5:f4db4cd245e3 268 port.printf("D%c%c12345678901234567890\n",27,30);
ladner 1:0eaa7682f7e1 269 }
ladner 1:0eaa7682f7e1 270 }
ladner 1:0eaa7682f7e1 271