Inhaltsverzeichnis
Arrays als Byte-Array
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 | #include “Arduino_LED_Matrix.h” int TASTER = 7; /* Minimum und Maximum der Zufallszahlen ermittelde Zahl wird immer nach unten gerundet -> maximaler Wert muss 7 sein */ int Minimum = 1; int Maximum = 7; // Name der Matrix ArduinoLEDMatrix Matrix; // Start-Button byte StartButton[8][12] = { { 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0 }, { 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0 }, { 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 0 }, { 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 0 }, { 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0 }, { 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0 } }; byte eins[8][12] = { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0 }, { 0, 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0, 0, 0, 0, 0, 1, 1 }, { 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1 } }; byte fuenf[8][12] = { { 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1 }, { 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1 }, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, { 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1 }, { 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1 } }; byte sechs[8][12] = { { 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1 }, { 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1 }, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, { 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1 }, { 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1 } }; void setup() { Matrix.begin(); // Zufallsgenerator starten randomSeed(A0); pinMode(TASTER, INPUT_PULLUP); // Start-Button anzeigen Matrix.renderBitmap(StartButton, 8, 12); } void loop() { // Zustand des Tasters lesen int TasterLesen = digitalRead(TASTER); if (TasterLesen == LOW) { delay(200); // Würfeleffekt for (int i = 0; i < 5; i++) { Wuerfeln(); delay(200); } } } void Wuerfeln() { // Zufallszahl ermitteln int Zahl = random(Minimum, Maximum); // Abfrage der gewürfelten Zahl switch (Zahl) { case 1: Matrix.renderBitmap(eins, 8, 12); break; case 2: Matrix.renderBitmap(zwei, 8, 12); break; case 3: Matrix.renderBitmap(drei, 8, 12); break; case 4: Matrix.renderBitmap(vier, 8, 12); break; case 5: Matrix.renderBitmap(vier, 8, 12); break; case 6: Matrix.renderBitmap(sechs, 8, 12); break; } } |
Arrays mit Matrix-Editor erstellt
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 | #include “Arduino_LED_Matrix.h” int TASTER = 7; /* Minimum und Maximum der Zufallszahlen ermittelde Zahl wird immer nach unten gerundet -> maximaler Wert muss 7 sein */ int Minimum = 1; int Maximum = 7; // Name der Matrix ArduinoLEDMatrix Matrix; // Array Start-Button const unsigned long StartButton[] = { 0x6009010, 0x82642641, 0x8090060, }; const unsigned long eins[] = { 0x0, 0x600600, 0x0 }; const unsigned long zwei[] = { 0x300300, 0x0, 0xc00c00 }; const unsigned long drei[] = { 0x300300, 0x600600, 0xc00c00, }; const unsigned long vier[] = { 0xc03c0300, 0x0, 0xc03c03 }; const unsigned long fuenf[] = { 0xc03c0300, 0x600600, 0xc03c03 }; const unsigned long sechs[] = { 0xc63c6300, 0x0, 0xc63c63 }; void setup() { Matrix.begin(); // Zufallsgenerator starten randomSeed(A0); pinMode(TASTER, INPUT_PULLUP); Matrix.loadFrame(StartButton); } void loop() { int TasterLesen = digitalRead(TASTER); if (TasterLesen == LOW) { delay(200); // Würfeleffekt for (int i = 0; i < 5; i++) { Wuerfeln(); delay(200); } } } void Wuerfeln() { int Zahl = random(Minimum, Maximum); switch (Zahl) { case 1: Matrix.loadFrame(eins); break; case 2: Matrix.loadFrame(zwei); break; case 3: Matrix.loadFrame(drei); break; case 4: Matrix.loadFrame(vier); break; case 5: Matrix.loadFrame(fuenf); break; case 6: Matrix.loadFrame(sechs); break; } } |
Letzte Aktualisierung: