123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173 |
- /*
- Arduino Spiel
- Autor: Zhao Xue
- Letzte Änderung: 12.07.2022
- Zweck: Beleg 3
- */
- unsigned char gesamtpunktzahl;
- const int red = 13, blue = 12, green = 11;
- byte wahl;
- int eingabe[10];
- int rand(void);
- bool prufmode=false;
- bool gameover=false;
- void setup()
- {
- gesamtpunktzahl = 0;
- pinMode(red, OUTPUT);
- pinMode(green, OUTPUT);
- pinMode(blue, OUTPUT);
- pinMode(10, INPUT_PULLUP);
- pinMode(9, INPUT_PULLUP);
- pinMode(8, INPUT_PULLUP);
- pinMode(7, INPUT_PULLUP);
- pinMode(6, INPUT_PULLUP);
- pinMode(5, INPUT_PULLUP);
- pinMode(4, INPUT_PULLUP);
- pinMode(3, INPUT_PULLUP);
- pinMode(2, INPUT_PULLUP);
- pinMode(1, INPUT_PULLUP);
- resetAllPins();
- }
- void resetAllPins()
- {
- // alle Pins auf definierte Werte setzen (sonst wissen wir nicht, welchen Wert sie gerade haben.)
- digitalWrite(red, LOW);
- digitalWrite(green, LOW);
- digitalWrite(blue, LOW);
- // Alle nachfolgenden Pins werden auf HIGH gesetzt, sodass sie auf ein GND/Masse-Signal reagieren können.
- digitalWrite(1, HIGH);
- digitalWrite(2, HIGH);
- digitalWrite(3, HIGH);
- digitalWrite(4, HIGH);
- digitalWrite(5, HIGH);
- digitalWrite(6, HIGH);
- digitalWrite(7, HIGH);
- digitalWrite(8, HIGH);
- digitalWrite(9, HIGH);
- digitalWrite(10, HIGH);
- }
- void blink(const int *pin)
- {
- digitalWrite(*pin, HIGH);
- delay(500);
- digitalWrite(*pin, LOW);
- delay(500);
- }
- void loop() //Schleife der 2 Level
- {
- wahl=menu();
- if(wahl==2)
- {
- game();}
- else if (wahl==3)
- {game();}
- resetAllPins();
-
- }
- byte menu() //Erstellung des Menue
- {
-
- blink(&green); //Erscheinung der Leuchte
- blink(&green);
- blink(&red);
- blink(&red);
- blink(&red);
- if (digitalRead(2) == LOW) //Einfacher Mode
- {
- for(int i=1;i<=2;i++)
- {digitalWrite(red, HIGH);digitalWrite(green, HIGH);digitalWrite(blue, HIGH);
- delay(500);
- digitalWrite(red, LOW);digitalWrite(green, LOW);digitalWrite(blue, LOW);
- delay(500);
- }
- return 2;
- }
- else if (digitalRead(3) == LOW)
- {
- for(int i=1;i<=3;i++)
- {digitalWrite(red, HIGH);digitalWrite(green, HIGH);digitalWrite(blue, HIGH);
- delay(500);
- digitalWrite(red, LOW);digitalWrite(green, LOW);digitalWrite(blue, LOW);
- delay(500);}
- return 3;
- }
- else
- {return 0;}
- }
- void game()
- { int j=0,k=0;
- for(;;){
-
- if(!prufmode)
- {
- digitalWrite(green, HIGH);
- for(int i=1;i<=10;i++)
- {if (digitalRead(i) == LOW)
- {
- for(int s=1;s<=i;s++){
- blink(&green);
- }
- eingabe[j]=i;
- blink(&green);
- prufmode=true;
- j++;k=0;
- digitalWrite(green, LOW);
- if(wahl==3){ //harte Mode
- int a=rand()%10+1;
- eingabe[j]=a;
- j++;k=0;
- for(int i=1;i<=a;i++){
- blink(&red);}
- prufmode=true;
-
- }
-
- }
- }
- }
- else
- {digitalWrite(green, LOW);digitalWrite(blue, HIGH);
- for(int i=1;i<=10;i++)
- {if (digitalRead(i) == LOW)
- {
- if(eingabe[k]==i)
- {
- digitalWrite(blue, LOW);delay(500);digitalWrite(blue, HIGH);
- k++;
- }
- else
- {gameover=true;}
- }
- }
-
- if(k==j)
- prufmode=false;
- }
- if(gameover)
-
- { for(int i=1;i<=j;i++){
- digitalWrite(red, HIGH);digitalWrite(green, HIGH);digitalWrite(blue, HIGH);
- delay(500);
- digitalWrite(red, LOW);digitalWrite(green, LOW);digitalWrite(blue, LOW);
- delay(500);
- }
- for(int i=0;i>10;i++)
- {eingabe[i]=0;}gameover=false;prufmode=false;
- break;
- }
- resetAllPins();
-
- }
-
- }
|