a
Dependencies: Led-libary TextLCD mbed
Fork of Mbed-Mensch-8 by
Diff: main.cpp
- Revision:
- 11:caa67a0ab7bd
- Parent:
- 10:f635972952e0
- Child:
- 12:7b480ec47c4c
diff -r f635972952e0 -r caa67a0ab7bd main.cpp --- a/main.cpp Sun Mar 13 00:18:29 2016 +0000 +++ b/main.cpp Sun Mar 13 19:44:04 2016 +0000 @@ -8,28 +8,25 @@ AnalogIn ldr(P0_12); AnalogIn poti(P0_11); //BusOut rgb(P0_9,P1_15,P0_21); -//BusIn btn(P1_16,P0_23,P0_10,P0_15); RGBOut rgb(P0_21,P0_9,P1_15); //Old: P0_13 LedOut Feld (P1_23);//P1_23 ->14 LedOut Home (P1_20);//P1_20->13 LedOut Dice (P1_21);//P1_21->12 -//-> Würfel (ersten 3 LED in Binär-4. LED für 7. Zustand), Spieler, Start, Ziel, Referenz(auch RGB am board) -// übrige 8 LED für zeit-Anzeige des Zuges einer KI +//-> Würfel (ersten 3 LED in Binär-4. LED für 7. Zustand), Spieler, Referenz(auch RGB am board) InterruptIn Button0(P0_1); InterruptIn Button1(P1_16); InterruptIn Button2(P0_23); InterruptIn Button3(P0_10); InterruptIn Button4(P0_15); - +BusIn btn(P1_16,P0_23,P0_10,P0_15,P0_1); +//Dice Timer Random; Timer RandomDice; Ticker DiceAnim; -void DiceStart(); -void DiceStop(); void DiceRun(); void setDice(char number); void DicePrint(); @@ -39,7 +36,7 @@ char diceTick = 0; char diceNum = 0; int16_t diceDecode [7]= {0x1,0x88,0x89,0xAA,0xAB,0x1BA,0x154}; - +//Game #define Feldgrose 10 #define Spieler 4 #define Steine 4 @@ -53,28 +50,111 @@ char moglich[Steine]; char selected; //der aktuell ausgewählte Zug char Field[Spieler*Feldgrose]; //Enthält den Index für PlayPos (nur das 'normale' Spielfend) -uint32_t Farben[Spieler]; //Berechnete Hellichkeiten der Speiler fertig zur Ausgabe... -uint32_t Background = 0; //Hintergrund (Leerfeld) -uint32_t DiseC = 0x00FF00; //Würfelfarbe void FieldPrint(); //Ausgabe auf Com-Port void FieldGenerate(); //Berechnung von PlayPos auf Start, Ziel, Field void FeldPrint(); //Ausgabe von Field auf den Led-Streifen (Feld) der Farben void GameCal(); -void moveNext(); -void moveLast(); Ticker MoveAnim; void MoveRun(); char MoveShow; -void MoveDo(); void ColorPrint(uint32_t color); - +//Animations char AnimField[Spieler*Feldgrose]; char AnimStart[Spieler*Steine]; char AnimZiel[Spieler*Steine]; char AnimPos[Spieler*Steine]; char AnimDo; //Feld_Animieren,Start Animieren, Ziel Animierenw void AnimCal(); +//Core Interactions void reset(); +void MoveDo(); +void moveNext(); +void moveLast(); +void DiceStart(); +void DiceStop(); +//Button entprellung (funktioniert nicht...) +void btn0(); +void btn1(); +void btn2(); +void btn3(); +void btn4(); +char btnLast; +//Farben +uint32_t Farben[Spieler]; //Berechnete Hellichkeiten der Speiler fertig zur Ausgabe... +uint32_t Background = 0; //Hintergrund (Leerfeld) +uint32_t DiseC = 0x00FF00; //Würfelfarbe +void ColorPrint(uint32_t color); //vorher den Header senden (manuell...) + + +void btn0() +{ + if((btnLast&0x10)==(btn&0x10)) + return; + else + { + if((btn&0x10)>0) + reset(); + else + /*DoNothing*/; + } + btnLast=(btnLast&(0x1F-0x10))|(btn&0x10); +} + +void btn1() +{ + if((btnLast&0x01)==(btn&0x01)) + return; + else + { + if((btn&0x01)>0) + DiceStart(); + else + DiceStop(); + } + btnLast=(btnLast&(0x1F-0x01))|(btn&0x01); +} + +void btn2() +{ + if((btnLast&0x02)==(btn&0x02)) + return; + else + { + if((btn&0x02)>0) + moveNext(); + else + /*DoNothing*/; + } + btnLast=(btnLast&(0x1F-0x02))|(btn&0x02); +} + +void btn3() +{ + if((btnLast&0x04)==(btn&0x04)) + return; + else + { + if((btn&0x04)>0) + moveLast(); + else + /*DoNothing*/; + } + btnLast=(btnLast&(0x1F-0x04))|(btn&0x04); +} + +void btn4() +{ + if((btnLast&0x08)==(btn&0x08)) + return; + else + { + if((btn&0x08)>0) + MoveDo(); + else + /*DoNothing*/; + } + btnLast=(btnLast&(0x1F-0x08))|(btn&0x08); +} void reset() { @@ -94,85 +174,6 @@ FeldPrint(); } -void btn2() -{ - for(char i = 0;i<Spieler;i++) - { - PlayPos[i*Spieler]=Steine+Spieler*Feldgrose; - PlayPos[i*Spieler+1]=Steine+Spieler*Feldgrose+1; - PlayPos[i*Spieler+2]=Spieler*Feldgrose + 2; - PlayPos[i*Spieler+3]=Steine+Spieler*Feldgrose+3; - } - FieldGenerate(); - FieldPrint(); - FeldPrint(); - /* - for(char i = 0; i<Spieler;i++) - for(char j = 0; j<Steine;j++) - Start[(i<<2)|j] = ((i<<2)|j)+1; - for(char i = 0; i<Spieler;i++) - for(char j = 0; j<Steine;j++) - Ziel[(i<<2)|j] = ((i<<2)|j)+1; - FeldPrint(); - */ - /* - Drann = 0; - PlayPos[1]=Steine+Feldgrose*Spieler; - //PlayPos[2]=Steine+Feldgrose*Spieler+1; - PlayPos[3]=Steine+Feldgrose*Spieler+2; - PlayPos[0]=Steine+Feldgrose*Spieler-1; - FieldGenerate(); - FieldPrint(); - FeldPrint(); - */ -} - -void btn3() -{ - /* - diceNum=2; - diceEn=2; - Drann = 1; - PlayPos[(1<<2)+0]=5; - PlayPos[(1<<2)+1]=7; - PlayPos[(1<<2)+2]=10; - PlayPos[(1<<2)+3]=12; - DicePrint(); - FieldGenerate(); - FieldPrint(); - FeldPrint(); - GameCal(); - */ - /* - port.printf("W%c%c\n",27+0x3E,27+0x7); - for(char i=0;i<Spieler;i++) - { - port.printf("w"); - ColorPrint(Farben[i]); - wait(1); - } - */ - diceEn=5; -} - -void btn4() -{ - /* - for(char i = 0;i<Spieler;i++) - PlayPos[i<<2]=4; - FieldGenerate(); - FieldPrint(); - */ - myled = 0; - rgb.set(0,0,0); - port.printf("LBtn 4 Pressed\n"); -} - -void btn4_() -{ - port.printf("LBtn 4 Released\n"); -} - void Control() { while(port.readable ()) @@ -233,15 +234,23 @@ //.attach(&main,[sek]); //.attach_us(&main,[micro-sec]); //.detach(); + Button0.mode(PullDown); + Button1.mode(PullDown); + Button2.mode(PullDown); + Button3.mode(PullDown); + Button4.mode(PullDown); + wait(0.01); Button0.rise(&reset); - Button1.rise(&DiceStart); - Button1.fall(&DiceStop); + Button1.rise(&btn1); + Button1.fall(&btn1); Button2.rise(&btn2); + Button2.fall(&btn2); Button3.rise(&btn3); + Button3.fall(&btn3); Button4.rise(&btn4); - Button4.fall(&btn4_); + Button4.fall(&btn4); //myled = 0xFFF; port.baud(76800); @@ -807,6 +816,11 @@ port.printf("LCount: %d\n",count); } } + else //Fahren nicht möglich,spieler am Feld & 6 gewürfelt + { + if(diceNum==6) + diceEn=0; + } } }