|
@@ -1,11 +1,11 @@
|
|
/*
|
|
/*
|
|
Arduino Spiel
|
|
Arduino Spiel
|
|
Autor: Johannes Tümler, Janek Franz, Marvin Richter
|
|
Autor: Johannes Tümler, Janek Franz, Marvin Richter
|
|
- Letzte Änderung: 14.07.2020
|
|
|
|
|
|
+ Letzte Änderung: 18.07.2020
|
|
Zweck: Beleg 3 Hilfscode für den Start
|
|
Zweck: Beleg 3 Hilfscode für den Start
|
|
*/
|
|
*/
|
|
|
|
|
|
-unsigned char gesamtpunktzahl;
|
|
|
|
|
|
+unsigned char gesamtpunktzahl; //Festlegen aller Variablen die verwendet werden
|
|
byte x;
|
|
byte x;
|
|
byte y;
|
|
byte y;
|
|
byte lauf;
|
|
byte lauf;
|
|
@@ -16,7 +16,6 @@ const int red = 13, blue = 11, green = 12;
|
|
|
|
|
|
void setup()
|
|
void setup()
|
|
{
|
|
{
|
|
- Serial.begin(9600);
|
|
|
|
gesamtpunktzahl = 0;
|
|
gesamtpunktzahl = 0;
|
|
randomSeed(analogRead(0));
|
|
randomSeed(analogRead(0));
|
|
pinMode(red, OUTPUT);
|
|
pinMode(red, OUTPUT);
|
|
@@ -66,10 +65,9 @@ void blink(const int *pin)
|
|
|
|
|
|
void loop()
|
|
void loop()
|
|
{
|
|
{
|
|
-
|
|
|
|
- if(digitalRead(0) == HIGH)
|
|
|
|
- {
|
|
|
|
- blink(&green);
|
|
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ blink(&green); //Hauptmenüblinksequenz + setzen von Pin 2 auf HIGH da sonst Bugs entstehen
|
|
blink(&green);
|
|
blink(&green);
|
|
blink(&red);
|
|
blink(&red);
|
|
blink(&red);
|
|
blink(&red);
|
|
@@ -78,23 +76,55 @@ void loop()
|
|
x = 0;
|
|
x = 0;
|
|
y = 0;
|
|
y = 0;
|
|
|
|
|
|
- digitalWrite(0,LOW);
|
|
|
|
|
|
+ digitalWrite(2,HIGH);
|
|
|
|
|
|
|
|
|
|
- }
|
|
|
|
|
|
+
|
|
|
|
|
|
|
|
|
|
- if (digitalRead(2) == LOW)
|
|
|
|
|
|
+ if (digitalRead(2) == LOW) //Überwechsel in Level 1 wenn Pin 2 LOW ist
|
|
{
|
|
{
|
|
digitalWrite(2,HIGH);
|
|
digitalWrite(2,HIGH);
|
|
|
|
+ delay(1000);
|
|
|
|
+ digitalWrite(red,HIGH);
|
|
|
|
+ digitalWrite(green,HIGH);
|
|
|
|
+ digitalWrite(blue,HIGH);
|
|
|
|
+ delay(1000);
|
|
|
|
+ digitalWrite(red,LOW);
|
|
|
|
+ digitalWrite(green,LOW);
|
|
|
|
+ digitalWrite(blue,LOW);
|
|
|
|
+ delay(1000);
|
|
|
|
+ digitalWrite(red,HIGH);
|
|
|
|
+ digitalWrite(green,HIGH);
|
|
|
|
+ digitalWrite(blue,HIGH);
|
|
|
|
+ delay(1000);
|
|
|
|
+ digitalWrite(red,LOW);
|
|
|
|
+ digitalWrite(green,LOW);
|
|
|
|
+ digitalWrite(blue,LOW);
|
|
level1();
|
|
level1();
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- if (digitalRead(3) == LOW)
|
|
|
|
|
|
+ if (digitalRead(3) == LOW) // Wechsel Level 2 wenn Pin LOW
|
|
{
|
|
{
|
|
digitalWrite(3,HIGH);
|
|
digitalWrite(3,HIGH);
|
|
- level2();
|
|
|
|
|
|
+ delay(1000);
|
|
|
|
+ digitalWrite(red,HIGH);
|
|
|
|
+ digitalWrite(green,HIGH);
|
|
|
|
+ digitalWrite(blue,HIGH);
|
|
|
|
+ delay(1000);
|
|
|
|
+ digitalWrite(red,LOW);
|
|
|
|
+ digitalWrite(green,LOW);
|
|
|
|
+ digitalWrite(blue,LOW);
|
|
|
|
+ delay(1000);
|
|
|
|
+ digitalWrite(red,HIGH);
|
|
|
|
+ digitalWrite(green,HIGH);
|
|
|
|
+ digitalWrite(blue,HIGH);
|
|
|
|
+ delay(1000);
|
|
|
|
+ digitalWrite(red,LOW);
|
|
|
|
+ digitalWrite(green,LOW);
|
|
|
|
+ digitalWrite(blue,LOW);
|
|
|
|
+ level2();
|
|
|
|
|
|
|
|
|
|
}
|
|
}
|
|
@@ -107,35 +137,28 @@ void loop()
|
|
resetAllPins();
|
|
resetAllPins();
|
|
}
|
|
}
|
|
|
|
|
|
-void level1()
|
|
|
|
|
|
+void level1() //Erzeugung der Schiffskoordinaten sowie Wechsel in Festlegung der ersten x Koordinate
|
|
{
|
|
{
|
|
- Serial.println("Level 1");
|
|
|
|
if(x == 0 && y == 0){
|
|
if(x == 0 && y == 0){
|
|
x = random(1,6);
|
|
x = random(1,6);
|
|
y = random(1,6);
|
|
y = random(1,6);
|
|
- Serial.println(String(x));
|
|
|
|
- Serial.println(String(y));
|
|
|
|
}
|
|
}
|
|
coordsx1();
|
|
coordsx1();
|
|
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
-void level2()
|
|
|
|
|
|
+void level2() //Erzeugung der Schiffskoordinaten sowie Wechsel in Festlegung der ersten x Koordinate
|
|
{
|
|
{
|
|
- Serial.print("Level 2");
|
|
|
|
if(x == 0 && y == 0){
|
|
if(x == 0 && y == 0){
|
|
x = random(1,6);
|
|
x = random(1,6);
|
|
y = random(1,6);
|
|
y = random(1,6);
|
|
}
|
|
}
|
|
digitalWrite(3,HIGH);
|
|
digitalWrite(3,HIGH);
|
|
- Serial.println("Anfangs Koords");
|
|
|
|
- Serial.println(String(x));
|
|
|
|
- Serial.println(String(y));
|
|
|
|
coordsx2();
|
|
coordsx2();
|
|
}
|
|
}
|
|
|
|
|
|
-void coordsx1()
|
|
|
|
|
|
+void coordsx1() //Festlegung der eingegebenen x Koordinate durch LOW setzen des entsprechenden Pins durch den Anwender sowie weiterschleifung in die y Festlegung
|
|
{
|
|
{
|
|
|
|
|
|
while (xsetz == 0){
|
|
while (xsetz == 0){
|
|
@@ -184,7 +207,7 @@ void coordsx1()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-void coordsy1()
|
|
|
|
|
|
+void coordsy1() //Festlegung der eingegebenen y Koordinate durch LOW setzen des entsprechenden Pins durch den Anwender sowie Schusssequenz und Weitergabe in die Positionsüberprüfung
|
|
{
|
|
{
|
|
digitalWrite(blue, HIGH);
|
|
digitalWrite(blue, HIGH);
|
|
while (ysetz == 0){
|
|
while (ysetz == 0){
|
|
@@ -223,8 +246,6 @@ void coordsy1()
|
|
ysetz = 5;
|
|
ysetz = 5;
|
|
|
|
|
|
}
|
|
}
|
|
- Serial.println(String(xsetz));
|
|
|
|
- Serial.println(String(ysetz));
|
|
|
|
}
|
|
}
|
|
delay(1000);
|
|
delay(1000);
|
|
digitalWrite(blue,HIGH);
|
|
digitalWrite(blue,HIGH);
|
|
@@ -232,19 +253,18 @@ void coordsy1()
|
|
delay(200);
|
|
delay(200);
|
|
digitalWrite(blue,LOW);
|
|
digitalWrite(blue,LOW);
|
|
digitalWrite(green,LOW);
|
|
digitalWrite(green,LOW);
|
|
|
|
+ delay(500);
|
|
posi1();
|
|
posi1();
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
-void posi1()
|
|
|
|
|
|
+void posi1() // Positionsabgleich mit den Schiffskoordinaten sowie Angabe der Entfernung und visuelle Ausgabe dieser und Rückschleifung bei Fehlschuss
|
|
{
|
|
{
|
|
gesamtpunktzahl ++;
|
|
gesamtpunktzahl ++;
|
|
if(x == xsetz && y == ysetz)
|
|
if(x == xsetz && y == ysetz)
|
|
{
|
|
{
|
|
- Serial.print("Treffer");
|
|
|
|
xsetz = 0;
|
|
xsetz = 0;
|
|
ysetz = 0;
|
|
ysetz = 0;
|
|
- digitalWrite(2, HIGH);
|
|
|
|
digitalWrite(6, HIGH);
|
|
digitalWrite(6, HIGH);
|
|
digitalWrite(7, HIGH);
|
|
digitalWrite(7, HIGH);
|
|
digitalWrite(8, HIGH);
|
|
digitalWrite(8, HIGH);
|
|
@@ -255,11 +275,9 @@ void posi1()
|
|
else if((x + 1 == xsetz or x - 1 == xsetz or x == xsetz)&& (y == ysetz or y + 1 == ysetz or y - 1 == ysetz))
|
|
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);
|
|
digitalWrite(red, HIGH);
|
|
- Serial.print("1");
|
|
|
|
delay(2000);
|
|
delay(2000);
|
|
xsetz = 0;
|
|
xsetz = 0;
|
|
ysetz = 0;
|
|
ysetz = 0;
|
|
- digitalWrite(2,HIGH);
|
|
|
|
digitalWrite(6, HIGH);
|
|
digitalWrite(6, HIGH);
|
|
digitalWrite(7, HIGH);
|
|
digitalWrite(7, HIGH);
|
|
digitalWrite(8, HIGH);
|
|
digitalWrite(8, HIGH);
|
|
@@ -271,11 +289,9 @@ void posi1()
|
|
else if((x + 2 == xsetz or x - 2 == xsetz or x == xsetz)&& (y == ysetz or y + 2 == ysetz or y - 2 == ysetz))
|
|
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);
|
|
digitalWrite(blue, HIGH);
|
|
- Serial.print("2");
|
|
|
|
delay(2000);
|
|
delay(2000);
|
|
xsetz = 0;
|
|
xsetz = 0;
|
|
ysetz = 0;
|
|
ysetz = 0;
|
|
- digitalWrite(2, HIGH);
|
|
|
|
digitalWrite(6, HIGH);
|
|
digitalWrite(6, HIGH);
|
|
digitalWrite(7, HIGH);
|
|
digitalWrite(7, HIGH);
|
|
digitalWrite(8, HIGH);
|
|
digitalWrite(8, HIGH);
|
|
@@ -288,7 +304,6 @@ void posi1()
|
|
{
|
|
{
|
|
xsetz = 0;
|
|
xsetz = 0;
|
|
ysetz = 0;
|
|
ysetz = 0;
|
|
- digitalWrite(2, HIGH);
|
|
|
|
digitalWrite(6, HIGH);
|
|
digitalWrite(6, HIGH);
|
|
digitalWrite(7, HIGH);
|
|
digitalWrite(7, HIGH);
|
|
digitalWrite(8, HIGH);
|
|
digitalWrite(8, HIGH);
|
|
@@ -298,7 +313,7 @@ void posi1()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-void gewonnen()
|
|
|
|
|
|
+void gewonnen() //Blinkablauf für Fall das getroffen wurde sowie Sprung an Anfang des Programms
|
|
{
|
|
{
|
|
|
|
|
|
for(byte lauf = 3; lauf >= 1;lauf--)
|
|
for(byte lauf = 3; lauf >= 1;lauf--)
|
|
@@ -326,11 +341,10 @@ void gewonnen()
|
|
delay(300);
|
|
delay(300);
|
|
|
|
|
|
}
|
|
}
|
|
-
|
|
|
|
- loop();
|
|
|
|
|
|
+ software_Reset();
|
|
}
|
|
}
|
|
|
|
|
|
-void coordsx2()
|
|
|
|
|
|
+void coordsx2() //siehe coordsx1
|
|
{
|
|
{
|
|
|
|
|
|
while (xsetz == 0){
|
|
while (xsetz == 0){
|
|
@@ -379,7 +393,7 @@ void coordsx2()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-void coordsy2()
|
|
|
|
|
|
+void coordsy2() //siehe coordsy1
|
|
{
|
|
{
|
|
digitalWrite(blue, HIGH);
|
|
digitalWrite(blue, HIGH);
|
|
while (ysetz == 0){
|
|
while (ysetz == 0){
|
|
@@ -418,8 +432,6 @@ void coordsy2()
|
|
ysetz = 5;
|
|
ysetz = 5;
|
|
|
|
|
|
}
|
|
}
|
|
- Serial.println(String(xsetz));
|
|
|
|
- Serial.println(String(ysetz));
|
|
|
|
}
|
|
}
|
|
delay(1000);
|
|
delay(1000);
|
|
digitalWrite(blue,HIGH);
|
|
digitalWrite(blue,HIGH);
|
|
@@ -427,19 +439,18 @@ void coordsy2()
|
|
delay(200);
|
|
delay(200);
|
|
digitalWrite(blue,LOW);
|
|
digitalWrite(blue,LOW);
|
|
digitalWrite(green,LOW);
|
|
digitalWrite(green,LOW);
|
|
|
|
+ delay(500);
|
|
posi2();
|
|
posi2();
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
-void posi2()
|
|
|
|
|
|
+void posi2() //Positionsüberprüfung wie in posi 1 jedoch weiterschleifung zur Bewegung des Schiffes
|
|
{
|
|
{
|
|
gesamtpunktzahl ++;
|
|
gesamtpunktzahl ++;
|
|
if(x == xsetz && y == ysetz)
|
|
if(x == xsetz && y == ysetz)
|
|
{
|
|
{
|
|
- Serial.print("Treffer");
|
|
|
|
xsetz = 0;
|
|
xsetz = 0;
|
|
ysetz = 0;
|
|
ysetz = 0;
|
|
- digitalWrite(2, HIGH);
|
|
|
|
digitalWrite(6, HIGH);
|
|
digitalWrite(6, HIGH);
|
|
digitalWrite(7, HIGH);
|
|
digitalWrite(7, HIGH);
|
|
digitalWrite(8, HIGH);
|
|
digitalWrite(8, HIGH);
|
|
@@ -450,11 +461,9 @@ void posi2()
|
|
else if((x + 1 == xsetz or x - 1 == xsetz or x == xsetz)&& (y == ysetz or y + 1 == ysetz or y - 1 == ysetz))
|
|
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);
|
|
digitalWrite(red, HIGH);
|
|
- Serial.print("1");
|
|
|
|
delay(2000);
|
|
delay(2000);
|
|
xsetz = 0;
|
|
xsetz = 0;
|
|
ysetz = 0;
|
|
ysetz = 0;
|
|
- digitalWrite(2,HIGH);
|
|
|
|
digitalWrite(6, HIGH);
|
|
digitalWrite(6, HIGH);
|
|
digitalWrite(7, HIGH);
|
|
digitalWrite(7, HIGH);
|
|
digitalWrite(8, HIGH);
|
|
digitalWrite(8, HIGH);
|
|
@@ -466,11 +475,9 @@ void posi2()
|
|
else if((x + 2 == xsetz or x - 2 == xsetz or x == xsetz)&& (y == ysetz or y + 2 == ysetz or y - 2 == ysetz))
|
|
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);
|
|
digitalWrite(blue, HIGH);
|
|
- Serial.print("2");
|
|
|
|
delay(2000);
|
|
delay(2000);
|
|
xsetz = 0;
|
|
xsetz = 0;
|
|
ysetz = 0;
|
|
ysetz = 0;
|
|
- digitalWrite(2, HIGH);
|
|
|
|
digitalWrite(6, HIGH);
|
|
digitalWrite(6, HIGH);
|
|
digitalWrite(7, HIGH);
|
|
digitalWrite(7, HIGH);
|
|
digitalWrite(8, HIGH);
|
|
digitalWrite(8, HIGH);
|
|
@@ -483,7 +490,6 @@ void posi2()
|
|
{
|
|
{
|
|
xsetz = 0;
|
|
xsetz = 0;
|
|
ysetz = 0;
|
|
ysetz = 0;
|
|
- digitalWrite(2, HIGH);
|
|
|
|
digitalWrite(6, HIGH);
|
|
digitalWrite(6, HIGH);
|
|
digitalWrite(7, HIGH);
|
|
digitalWrite(7, HIGH);
|
|
digitalWrite(8, HIGH);
|
|
digitalWrite(8, HIGH);
|
|
@@ -495,7 +501,7 @@ void posi2()
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
-void bewegung()
|
|
|
|
|
|
+void bewegung() //Randomzahl erzeugt von 1-8 für die Bewegungsmöglichkeiten die das Schiff hat in diesem Moment
|
|
{
|
|
{
|
|
bew = random(1,9);
|
|
bew = random(1,9);
|
|
|
|
|
|
@@ -586,12 +592,11 @@ void bewegung()
|
|
bewegung();
|
|
bewegung();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- Serial.print("Neue Koords");
|
|
|
|
- Serial.println(String(x));
|
|
|
|
- Serial.println(String(y));
|
|
|
|
coordsx2();
|
|
coordsx2();
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
-
|
|
|
|
|
|
+void software_Reset() //Sprung zurück an den Anfang des Programms
|
|
|
|
+{
|
|
|
|
+asm volatile ("jmp 0");
|
|
|
|
+}
|
|
|
|
|