|
@@ -1,18 +1,24 @@
|
|
|
/*
|
|
|
Arduino Spiel
|
|
|
- Autor: Johannes Tümler
|
|
|
- Letzte Änderung: 27.06.2020
|
|
|
+ Autor: Johannes Tümler, Janek Franz, Marvin Richter
|
|
|
+ Letzte Änderung: 14.07.2020
|
|
|
Zweck: Beleg 3 Hilfscode für den Start
|
|
|
*/
|
|
|
|
|
|
unsigned char gesamtpunktzahl;
|
|
|
byte x;
|
|
|
+byte y;
|
|
|
+byte lauf;
|
|
|
+byte xsetz;
|
|
|
+byte ysetz;
|
|
|
+byte bew;
|
|
|
const int red = 13, blue = 11, green = 12;
|
|
|
|
|
|
void setup()
|
|
|
{
|
|
|
Serial.begin(9600);
|
|
|
gesamtpunktzahl = 0;
|
|
|
+ randomSeed(analogRead(0));
|
|
|
pinMode(red, OUTPUT);
|
|
|
pinMode(green, OUTPUT);
|
|
|
pinMode(blue, OUTPUT);
|
|
@@ -69,6 +75,9 @@ void loop()
|
|
|
blink(&red);
|
|
|
blink(&red);
|
|
|
|
|
|
+ x = 0;
|
|
|
+ y = 0;
|
|
|
+
|
|
|
digitalWrite(0,LOW);
|
|
|
|
|
|
|
|
@@ -81,14 +90,6 @@ void loop()
|
|
|
level1();
|
|
|
|
|
|
}
|
|
|
-
|
|
|
- if (digitalRead(3) == LOW)
|
|
|
- {
|
|
|
- digitalWrite(3,HIGH);
|
|
|
- level2();
|
|
|
- delay(1000);
|
|
|
-
|
|
|
- }
|
|
|
|
|
|
if (digitalRead(5) == LOW) // Hier im Beispiel: Wenn ein Masse-Signal / GND an Pin 5 liegt, dann blinkt es.
|
|
|
{
|
|
@@ -100,8 +101,210 @@ void loop()
|
|
|
|
|
|
void level1()
|
|
|
{
|
|
|
- Serial.print("Level 1");
|
|
|
+ Serial.println("Level 1");
|
|
|
if(x == 0 && y == 0){
|
|
|
x = random(1,6);
|
|
|
y = random(1,6);
|
|
|
- }
|
|
|
+ Serial.println(String(x));
|
|
|
+ Serial.println(String(y));
|
|
|
+ }
|
|
|
+ coordsx1();
|
|
|
+
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+void coordsx1()
|
|
|
+{
|
|
|
+
|
|
|
+ while (xsetz == 0){
|
|
|
+ digitalWrite(green, HIGH);
|
|
|
+ if (digitalRead(6) == LOW)
|
|
|
+ {
|
|
|
+ digitalWrite(green, LOW);
|
|
|
+ xsetz = 1;
|
|
|
+ delay(500);
|
|
|
+ coordsy1();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (digitalRead(7) == LOW)
|
|
|
+ {
|
|
|
+ digitalWrite(green, LOW);
|
|
|
+ xsetz = 2;
|
|
|
+ delay(500);
|
|
|
+ coordsy1();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if (digitalRead(8) == LOW)
|
|
|
+ {
|
|
|
+ digitalWrite(green, LOW);
|
|
|
+ xsetz = 3;
|
|
|
+ delay(500);
|
|
|
+ coordsy1();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (digitalRead(9) == LOW)
|
|
|
+ {
|
|
|
+ digitalWrite(green, LOW);
|
|
|
+ xsetz = 4;
|
|
|
+ delay(500);
|
|
|
+ coordsy1();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (digitalRead(10) == LOW)
|
|
|
+ {
|
|
|
+ digitalWrite(green, LOW);
|
|
|
+ xsetz = 5;
|
|
|
+ delay(500);
|
|
|
+ coordsy1();
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+}
|
|
|
+
|
|
|
+void coordsy1()
|
|
|
+{
|
|
|
+ digitalWrite(blue, HIGH);
|
|
|
+ while (ysetz == 0){
|
|
|
+ if (digitalRead(6) == LOW)
|
|
|
+ {
|
|
|
+ digitalWrite(blue, LOW);
|
|
|
+ ysetz = 1;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ if (digitalRead(7) == LOW)
|
|
|
+ {
|
|
|
+ digitalWrite(blue, LOW);
|
|
|
+ ysetz = 2;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if (digitalRead(8) == LOW)
|
|
|
+ {
|
|
|
+ digitalWrite(blue, LOW);
|
|
|
+ ysetz = 3;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ if (digitalRead(9) == LOW)
|
|
|
+ {
|
|
|
+ digitalWrite(blue, LOW);
|
|
|
+ ysetz = 4;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ if (digitalRead(10) == LOW)
|
|
|
+ {
|
|
|
+ digitalWrite(blue, LOW);
|
|
|
+ ysetz = 5;
|
|
|
+
|
|
|
+ }
|
|
|
+ Serial.println(String(xsetz));
|
|
|
+ Serial.println(String(ysetz));
|
|
|
+ }
|
|
|
+ delay(1000);
|
|
|
+ digitalWrite(blue,HIGH);
|
|
|
+ digitalWrite(green,HIGH);
|
|
|
+ delay(200);
|
|
|
+ digitalWrite(blue,LOW);
|
|
|
+ digitalWrite(green,LOW);
|
|
|
+ posi1();
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+void posi1()
|
|
|
+{
|
|
|
+ gesamtpunktzahl ++;
|
|
|
+ if(x == xsetz && y == ysetz)
|
|
|
+ {
|
|
|
+ Serial.print("Treffer");
|
|
|
+ xsetz = 0;
|
|
|
+ ysetz = 0;
|
|
|
+ digitalWrite(2, HIGH);
|
|
|
+ digitalWrite(6, HIGH);
|
|
|
+ digitalWrite(7, HIGH);
|
|
|
+ digitalWrite(8, HIGH);
|
|
|
+ digitalWrite(9, HIGH);
|
|
|
+ digitalWrite(10, HIGH);
|
|
|
+ gewonnen();
|
|
|
+ }
|
|
|
+ else if((x + 1 == xsetz or x - 1 == xsetz or x == xsetz)&& (y == ysetz or y + 1 == ysetz or y - 1 == ysetz))
|
|
|
+ {
|
|
|
+ digitalWrite(red, HIGH);
|
|
|
+ Serial.print("1");
|
|
|
+ delay(2000);
|
|
|
+ xsetz = 0;
|
|
|
+ ysetz = 0;
|
|
|
+ digitalWrite(2,HIGH);
|
|
|
+ digitalWrite(6, HIGH);
|
|
|
+ digitalWrite(7, HIGH);
|
|
|
+ digitalWrite(8, HIGH);
|
|
|
+ digitalWrite(9, HIGH);
|
|
|
+ digitalWrite(10, HIGH);
|
|
|
+ digitalWrite(red, LOW);
|
|
|
+ coordsx1();
|
|
|
+ }
|
|
|
+ else if((x + 2 == xsetz or x - 2 == xsetz or x == xsetz)&& (y == ysetz or y + 2 == ysetz or y - 2 == ysetz))
|
|
|
+ {
|
|
|
+ digitalWrite(blue, HIGH);
|
|
|
+ Serial.print("2");
|
|
|
+ delay(2000);
|
|
|
+ xsetz = 0;
|
|
|
+ ysetz = 0;
|
|
|
+ digitalWrite(2, HIGH);
|
|
|
+ digitalWrite(6, HIGH);
|
|
|
+ digitalWrite(7, HIGH);
|
|
|
+ digitalWrite(8, HIGH);
|
|
|
+ digitalWrite(9, HIGH);
|
|
|
+ digitalWrite(10, HIGH);
|
|
|
+ digitalWrite(blue, LOW);
|
|
|
+ coordsx1();
|
|
|
+ }
|
|
|
+ else if ((x + 2 >= xsetz or x - 2 <= xsetz or x == xsetz)&& (y == ysetz or y + 2 >= ysetz or y - 2 <= ysetz))
|
|
|
+ {
|
|
|
+ xsetz = 0;
|
|
|
+ ysetz = 0;
|
|
|
+ digitalWrite(2, HIGH);
|
|
|
+ digitalWrite(6, HIGH);
|
|
|
+ digitalWrite(7, HIGH);
|
|
|
+ digitalWrite(8, HIGH);
|
|
|
+ digitalWrite(9, HIGH);
|
|
|
+ digitalWrite(10, HIGH);
|
|
|
+ coordsx1();
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void gewonnen()
|
|
|
+{
|
|
|
+
|
|
|
+ for(byte lauf = 3; lauf >= 1;lauf--)
|
|
|
+ {
|
|
|
+ digitalWrite(red,HIGH);
|
|
|
+ delay(100);
|
|
|
+ digitalWrite(red,LOW);
|
|
|
+ digitalWrite(green, HIGH);
|
|
|
+ delay(100);
|
|
|
+ digitalWrite(green,LOW);
|
|
|
+ digitalWrite(blue,HIGH);
|
|
|
+ delay(100);
|
|
|
+ digitalWrite(blue, LOW);
|
|
|
+ }
|
|
|
+ for(gesamtpunktzahl; gesamtpunktzahl >= 1;gesamtpunktzahl --)
|
|
|
+ {
|
|
|
+
|
|
|
+ digitalWrite(red,HIGH);
|
|
|
+ digitalWrite(green,HIGH);
|
|
|
+ digitalWrite(blue,HIGH);
|
|
|
+ delay(300);
|
|
|
+ digitalWrite(red,LOW);
|
|
|
+ digitalWrite(green,LOW);
|
|
|
+ digitalWrite(blue, LOW);
|
|
|
+ delay(300);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ loop();
|
|
|
+}
|
|
|
+
|