Inhaltsverzeichnis
ESP32-Wroom
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 | #include “Adafruit_NeoMatrix.h” // Pins ESP32-Wroom, für UNO anpassen #define RGBMatrixPin 15 #define TASTER 2 #define LAUTSPRECHER 26 // RGBMatrix -> Name der RGB-Matrix /* die wichtigsten Parameter: Parameter 1 = Breite der Matrix (8) Parameter 2 = Höhe der Matrix (8) Parameter 3 = Name des Daten-Pins (RGBMatrixPin) */ Adafruit_NeoMatrix RGBMatrix = Adafruit_NeoMatrix ( 8, 8, RGBMatrixPin, NEO_MATRIX_TOP + NEO_MATRIX_RIGHT + NEO_MATRIX_COLUMNS + NEO_MATRIX_PROGRESSIVE, NEO_GRB + NEO_KHZ800 ); // Farben definieren #define Rot RGBMatrix.Color(255, 0, 0) #define Gruen RGBMatrix.Color(0, 255, 0) #define Blau RGBMatrix.Color(0, 0, 255) #define Magenta RGBMatrix.Color(139, 0, 139) #define Pink RGBMatrix.Color(255, 20, 147) #define Weiss RGBMatrix.Color(255, 255, 255) #define Gelb RGBMatrix.Color(255, 255, 0) #define Schwarz RGBMatrix.Color(0, 0, 0) #define Rosa RGBMatrix.Color(236, 170, 170) #define Orange RGBMatrix.Color(255, 165, 0) // zufällige Farbe #define Zufallsfarbe RGBMatrix.Color(random(1, 255), random(1, 255), random(1, 255)) // Variablen: Farbe -> Farbe der Zahl, Zahl -> zufällig ermittelte Zahl int Farbe; int Zahl; // Array für die Zufallszahlen int ZahlWert[2]; // Startwert für die Anzahl der Durchläufe int Durchlauf = 0; // Variable für den Zusand des Tasters bool TasterGedrueckt = true; void setup() { pinMode(TASTER, INPUT_PULLUP); // Helligkeit der RGBMatrix RGBMatrix.setBrightness(30); // RGBMatrix starten RGBMatrix.begin(); // Zufallsgenerator starten randomSeed(analogRead(A0)); // Pfeil anzeigen RGBMatrix.drawFastHLine(0, 3, 8, Gelb); RGBMatrix.drawFastHLine(0, 4, 8, Gelb); RGBMatrix.drawPixel(6, 2, Gelb); RGBMatrix.drawPixel(6, 5, Gelb); RGBMatrix.show(); } void loop() { // solange der Taster gedrückt wird laufen zufällige Zahlen if (!digitalRead(TASTER)) { TasterGedrueckt = false; RGBMatrix.clear(); // ASCII-Werte der Zahlen: 49 = 1 … 57 = 9 Zahl = random(49, 57); // Farben der Zahlen definieren switch (Zahl) { case 49: Farbe = Rot; break; case 50: Farbe = Gruen; break; case 51: Farbe = Blau; break; case 52: Farbe = Magenta; break; case 53: Farbe = Pink; break; case 54: Farbe = Weiss; break; case 55: Farbe = Gelb; break; case 56: Farbe = Rosa; break; case 57: Farbe = Orange; break; } // Zahl anzeigen RGBMatrix.drawChar(2, 1, char(Zahl), Farbe, Schwarz, 1); RGBMatrix.show(); tone(LAUTSPRECHER, 1000, 30); delay(100); } // wenn der Taster nicht gedrückt wurde // und (&&) TasterGedrueckt false ist if (digitalRead(TASTER) && !TasterGedrueckt) { TasterGedrueckt = true; // aktuelle Zahl im Array speichern ZahlWert[Durchlauf] = Zahl; // wenn zwei Zahlen im Array gleich sind if (ZahlWert[0] == ZahlWert[1]) { RGBMatrix.clear(); // Pfeil anzeigen RGBMatrix.drawFastHLine(0, 3, 8, Gelb); RGBMatrix.drawFastHLine(0, 4, 8, Gelb); RGBMatrix.drawPixel(6, 2, Gelb); RGBMatrix.drawPixel(6, 5, Gelb); RGBMatrix.show(); delay(1000); RGBMatrix.clear(); // identische Zahlen anzeigen // erste Zahl anzeigen RGBMatrix.drawChar(2, 1, char(ZahlWert[0]), Farbe, Schwarz, 1); RGBMatrix.show(); delay(2000); RGBMatrix.clear(); // Pfeil anzeigen RGBMatrix.drawFastHLine(0, 3, 8, Gelb); RGBMatrix.drawFastHLine(0, 4, 8, Gelb); RGBMatrix.drawPixel(6, 2, Gelb); RGBMatrix.drawPixel(6, 5, Gelb); RGBMatrix.show(); delay(2000); RGBMatrix.clear(); // zweite Zahl anzeigen RGBMatrix.drawChar(2, 1, char(ZahlWert[1]), Farbe, Schwarz, 1); RGBMatrix.show(); delay(2000); // Smley RGBMatrix.clear(); RGBMatrix.drawCircle(4, 4, 3, Gelb); RGBMatrix.drawPixel(3, 3, Gelb); RGBMatrix.drawPixel(5, 3, Gelb); RGBMatrix.show(); // Melodie abspielen tone(LAUTSPRECHER, 100, 100); tone(LAUTSPRECHER, 200, 100); tone(LAUTSPRECHER, 300, 100); tone(LAUTSPRECHER, 400, 100); tone(LAUTSPRECHER, 300, 100); tone(LAUTSPRECHER, 200, 100); tone(LAUTSPRECHER, 100, 100); } // Durchlauf erhöhen Durchlauf ++; // wenn Durchlauf > 1 -> Wert zurücksetzen if (Durchlauf > 1) Durchlauf = 0; } } |
Wemos D1 Mini
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 | #include “Adafruit_NeoMatrix.h” // Pins ESP32-Wroom, für UNO anpassen #define RGBMatrixPin D1 #define TASTER D3 #define LAUTSPRECHER D2 // RGBMatrix -> Name de D2D2-Matrix /* die wichtigsten Parameter: Parameter 1 = Breite der Matrix (8) Parameter 2 = Höhe der Matrix (8) Parameter 3 = Name des Daten-Pins (RGBMatrixPin) */ Adafruit_NeoMatrix RGBMatrix = Adafruit_NeoMatrix ( 8, 8, RGBMatrixPin, NEO_MATRIX_TOP + NEO_MATRIX_RIGHT + NEO_MATRIX_COLUMNS + NEO_MATRIX_PROGRESSIVE, NEO_GRB + NEO_KHZ800 ); // Farben definieren #define Rot RGBMatrix.Color(255, 0, 0) #define Gruen RGBMatrix.Color(0, 255, 0) #define Blau RGBMatrix.Color(0, 0, 255) #define Magenta RGBMatrix.Color(139, 0, 139) #define Pink RGBMatrix.Color(255, 20, 147) #define Weiss RGBMatrix.Color(255, 255, 255) #define Gelb RGBMatrix.Color(255, 255, 0) #define Schwarz RGBMatrix.Color(0, 0, 0) #define Rosa RGBMatrix.Color(236, 170, 170) #define Orange RGBMatrix.Color(255, 165, 0) // zufällige Farbe #define Zufallsfarbe RGBMatrix.Color(random(1, 255), random(1, 255), random(1, 255)) // Variablen: Farbe -> Farbe der Zahl, Zahl -> zufällig ermittelte Zahl int Farbe; int Zahl; // Array für die Zufallszahlen int ZahlWert[2]; // Startwert für die Anzahl der Durchläufe int Durchlauf = 0; // Variable für den Zusand des Tasters bool TasterGedrueckt = true; void setup() { pinMode(TASTER, INPUT_PULLUP); // Helligkeit der RGBMatrix RGBMatrix.setBrightness(30); // RGBMatrix starten RGBMatrix.begin(); // Zufallsgenerator starten randomSeed(analogRead(A0)); // Pfeil anzeigen RGBMatrix.drawFastHLine(0, 3, 8, Gelb); RGBMatrix.drawFastHLine(0, 4, 8, Gelb); RGBMatrix.drawPixel(6, 2, Gelb); RGBMatrix.drawPixel(6, 5, Gelb); RGBMatrix.show(); } void loop() { // solange der Taster gedrückt wird laufen zufällige Zahlen if (!digitalRead(TASTER)) { TasterGedrueckt = false; RGBMatrix.clear(); // ASCII-Werte der Zahlen: 49 = 1 … 57 = 9 Zahl = random(49, 57); // Farben der Zahlen definieren switch (Zahl) { case 49: Farbe = Rot; break; case 50: Farbe = Gruen; break; case 51: Farbe = Blau; break; case 52: Farbe = Magenta; break; case 53: Farbe = Pink; break; case 54: Farbe = Weiss; break; case 55: Farbe = Gelb; break; case 56: Farbe = Rosa; break; case 57: Farbe = Orange; break; } // Zahl anzeigen RGBMatrix.drawChar(2, 1, char(Zahl), Farbe, Schwarz, 1); RGBMatrix.show(); tone(LAUTSPRECHER, 1000, 30); delay(100); } // wenn der Taster nicht gedrückt wurde // und (&&) TasterGedrueckt false ist if (digitalRead(TASTER) && !TasterGedrueckt) { TasterGedrueckt = true; // aktuelle Zahl im Array speichern ZahlWert[Durchlauf] = Zahl; // wenn zwei Zahlen im Array gleich sind if (ZahlWert[0] == ZahlWert[1]) { RGBMatrix.clear(); // Pfeil anzeigen RGBMatrix.drawFastHLine(0, 3, 8, Gelb); RGBMatrix.drawFastHLine(0, 4, 8, Gelb); RGBMatrix.drawPixel(6, 2, Gelb); RGBMatrix.drawPixel(6, 5, Gelb); RGBMatrix.show(); delay(1000); RGBMatrix.clear(); // identische Zahlen anzeigen // erste Zahl anzeigen RGBMatrix.drawChar(2, 1, char(ZahlWert[0]), Farbe, Schwarz, 1); RGBMatrix.show(); delay(2000); RGBMatrix.clear(); // Pfeil anzeigen RGBMatrix.drawFastHLine(0, 3, 8, Gelb); RGBMatrix.drawFastHLine(0, 4, 8, Gelb); RGBMatrix.drawPixel(6, 2, Gelb); RGBMatrix.drawPixel(6, 5, Gelb); RGBMatrix.show(); delay(2000); RGBMatrix.clear(); // zweite Zahl anzeigen RGBMatrix.drawChar(2, 1, char(ZahlWert[1]), Farbe, Schwarz, 1); RGBMatrix.show(); delay(2000); // Smley RGBMatrix.clear(); RGBMatrix.drawCircle(4, 4, 3, Gelb); RGBMatrix.drawPixel(3, 3, Gelb); RGBMatrix.drawPixel(5, 3, Gelb); RGBMatrix.show(); // Melodie abspielen tone(LAUTSPRECHER, 100, 100); tone(LAUTSPRECHER, 200, 100); tone(LAUTSPRECHER, 300, 100); tone(LAUTSPRECHER, 400, 100); tone(LAUTSPRECHER, 300, 100); tone(LAUTSPRECHER, 200, 100); tone(LAUTSPRECHER, 100, 100); } // Durchlauf erhöhen Durchlauf ++; // wenn Durchlauf > 1 -> Wert zurücksetzen if (Durchlauf > 1) Durchlauf = 0; } } |
Arduino UNO
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 | #include “Adafruit_NeoMatrix.h” // Pins ESP32-Wroom, für UNO anpassen #define RGBMatrixPin 7 #define TASTER 8 #define LAUTSPRECHER 9 // RGBMatrix -> Name der RGB-Matrix /* die wichtigsten Parameter: Parameter 1 = Breite der Matrix (8) Parameter 2 = Höhe der Matrix (8) Parameter 3 = Name des Daten-Pins (RGBMatrixPin) */ Adafruit_NeoMatrix RGBMatrix = Adafruit_NeoMatrix ( 8, 8, RGBMatrixPin, NEO_MATRIX_TOP + NEO_MATRIX_RIGHT + NEO_MATRIX_COLUMNS + NEO_MATRIX_PROGRESSIVE, NEO_GRB + NEO_KHZ800 ); // Farben definieren #define Rot RGBMatrix.Color(255, 0, 0) #define Gruen RGBMatrix.Color(0, 255, 0) #define Blau RGBMatrix.Color(0, 0, 255) #define Magenta RGBMatrix.Color(139, 0, 139) #define Pink RGBMatrix.Color(255, 20, 147) #define Weiss RGBMatrix.Color(255, 255, 255) #define Gelb RGBMatrix.Color(255, 255, 0) #define Schwarz RGBMatrix.Color(0, 0, 0) #define Rosa RGBMatrix.Color(236, 170, 170) #define Orange RGBMatrix.Color(255, 165, 0) // zufällige Farbe #define Zufallsfarbe RGBMatrix.Color(random(1, 255), random(1, 255), random(1, 255)) // Variablen: Farbe -> Farbe der Zahl, Zahl -> zufällig ermittelte Zahl int Farbe; int Zahl; // Array für die Zufallszahlen int ZahlWert[2]; // Startwert für die Anzahl der Durchläufe int Durchlauf = 0; // Variable für den Zusand des Tasters bool TasterGedrueckt = true; void setup() { pinMode(TASTER, INPUT_PULLUP); // Helligkeit der RGBMatrix RGBMatrix.setBrightness(30); // RGBMatrix starten RGBMatrix.begin(); // Zufallsgenerator starten randomSeed(analogRead(A0)); // Pfeil anzeigen RGBMatrix.drawFastHLine(0, 3, 8, Gelb); RGBMatrix.drawFastHLine(0, 4, 8, Gelb); RGBMatrix.drawPixel(6, 2, Gelb); RGBMatrix.drawPixel(6, 5, Gelb); RGBMatrix.show(); } void loop() { // solange der Taster gedrückt wird laufen zufällige Zahlen if (!digitalRead(TASTER)) { TasterGedrueckt = false; RGBMatrix.clear(); // ASCII-Werte der Zahlen: 49 = 1 … 57 = 9 Zahl = random(49, 57); // Farben der Zahlen definieren switch (Zahl) { case 49: Farbe = Rot; break; case 50: Farbe = Gruen; break; case 51: Farbe = Blau; break; case 52: Farbe = Magenta; break; case 53: Farbe = Pink; break; case 54: Farbe = Weiss; break; case 55: Farbe = Gelb; break; case 56: Farbe = Rosa; break; case 57: Farbe = Orange; break; } // Zahl anzeigen RGBMatrix.drawChar(2, 1, char(Zahl), Farbe, Schwarz, 1); RGBMatrix.show(); tone(LAUTSPRECHER, 1000, 30); delay(100); } // wenn der Taster nicht gedrückt wurde // und (&&) TasterGedrueckt false ist if (digitalRead(TASTER) && !TasterGedrueckt) { TasterGedrueckt = true; // aktuelle Zahl im Array speichern ZahlWert[Durchlauf] = Zahl; // wenn zwei Zahlen im Array gleich sind if (ZahlWert[0] == ZahlWert[1]) { RGBMatrix.clear(); // Pfeil anzeigen RGBMatrix.drawFastHLine(0, 3, 8, Gelb); RGBMatrix.drawFastHLine(0, 4, 8, Gelb); RGBMatrix.drawPixel(6, 2, Gelb); RGBMatrix.drawPixel(6, 5, Gelb); RGBMatrix.show(); delay(1000); RGBMatrix.clear(); // identische Zahlen anzeigen // erste Zahl anzeigen RGBMatrix.drawChar(2, 1, char(ZahlWert[0]), Farbe, Schwarz, 1); RGBMatrix.show(); delay(2000); RGBMatrix.clear(); // Pfeil anzeigen RGBMatrix.drawFastHLine(0, 3, 8, Gelb); RGBMatrix.drawFastHLine(0, 4, 8, Gelb); RGBMatrix.drawPixel(6, 2, Gelb); RGBMatrix.drawPixel(6, 5, Gelb); RGBMatrix.show(); delay(2000); RGBMatrix.clear(); // zweite Zahl anzeigen RGBMatrix.drawChar(2, 1, char(ZahlWert[1]), Farbe, Schwarz, 1); RGBMatrix.show(); delay(2000); // Smley RGBMatrix.clear(); RGBMatrix.drawCircle(4, 4, 3, Gelb); RGBMatrix.drawPixel(3, 3, Gelb); RGBMatrix.drawPixel(5, 3, Gelb); RGBMatrix.show(); // Melodie abspielen tone(LAUTSPRECHER, 100, 100); tone(LAUTSPRECHER, 200, 100); tone(LAUTSPRECHER, 300, 100); tone(LAUTSPRECHER, 400, 100); tone(LAUTSPRECHER, 300, 100); tone(LAUTSPRECHER, 200, 100); tone(LAUTSPRECHER, 100, 100); } // Durchlauf erhöhen Durchlauf ++; // wenn Durchlauf > 1 -> Wert zurücksetzen if (Durchlauf > 1) Durchlauf = 0; } } |
Letzte Aktualisierung: