|
@@ -0,0 +1,107 @@
|
|
|
|
+/*
|
|
|
|
+ Arduino Spiel
|
|
|
|
+ Autor: Johannes Tümler
|
|
|
|
+ Letzte Änderung: 27.06.2020
|
|
|
|
+ Zweck: Beleg 3 Hilfscode für den Start
|
|
|
|
+*/
|
|
|
|
+
|
|
|
|
+unsigned char gesamtpunktzahl;
|
|
|
|
+byte x;
|
|
|
|
+const int red = 13, blue = 11, green = 12;
|
|
|
|
+
|
|
|
|
+void setup()
|
|
|
|
+{
|
|
|
|
+ Serial.begin(9600);
|
|
|
|
+ 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);
|
|
|
|
+ pinMode(0, 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(0, HIGH);
|
|
|
|
+ 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()
|
|
|
|
+{
|
|
|
|
+
|
|
|
|
+ if(digitalRead(0) == HIGH)
|
|
|
|
+ {
|
|
|
|
+ blink(&green);
|
|
|
|
+ blink(&green);
|
|
|
|
+ blink(&red);
|
|
|
|
+ blink(&red);
|
|
|
|
+ blink(&red);
|
|
|
|
+
|
|
|
|
+ digitalWrite(0,LOW);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ if (digitalRead(2) == LOW)
|
|
|
|
+ {
|
|
|
|
+ digitalWrite(2,HIGH);
|
|
|
|
+ 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.
|
|
|
|
+ {
|
|
|
|
+ blink(&red);
|
|
|
|
+ digitalWrite(5, HIGH);
|
|
|
|
+ }
|
|
|
|
+ resetAllPins();
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void level1()
|
|
|
|
+{
|
|
|
|
+ Serial.print("Level 1");
|
|
|
|
+ if(x == 0 && y == 0){
|
|
|
|
+ x = random(1,6);
|
|
|
|
+ y = random(1,6);
|
|
|
|
+ }
|