Mit diesem Projekt zeige ich, wie Sie einen Ball auf einer 8 × 8 LED-Matrix steuern können.
Mit den beiden Potentiometern können Sie den Ball über die X- und Y-Achse der Matrix bewegen.
In diesem Projekt lernen Sie, wie Sie eine LED-Matrix verwenden und die Werte eines Potentiometers ablesen.
- Level - Anfänger / Mittelstufe 40%
- Dauer - 45/60 min 60%
- Kosten - 36,51 € abgeschlossen 30%
Schritt 1: Anforderungen
- 1X Arduino UNO
- 1X Brotboard
- 13X M/M-Überbrückungsdrähte
- 1X 8×8 LED-Matrix
- 2X 10K Potentiometer
Schritt 2: Bauen und Verkabeln
Schritt 3: Programmierung
Wenn alles richtig angeschlossen ist, können Sie mit dem Schreiben des Programms beginnen.
Es ist ein ziemlich großes Programm, aber es ist hauptsächlich konstant mit nur wenigen Werten, die sich ändern.
Dieser Code wird jetzt für eine LED-Matrix erstellt, die nur eine X- und eine Y-Achse hat.
Wenn Sie auch eine Z-Achse verwenden möchten, müssen Sie ein zusätzliches Potentiometer anschließen und dann den Code so einstellen, dass die Werte gelesen werden können.
Sie können den folgenden Code kopieren. Wir empfehlen jedoch, ihn selbst einzugeben, wenn Sie mehr darüber erfahren.
#include LedControl.h
// hier geben wir der LED-Matrix einen Namen und die E / A-Pins, die sie steuern kann
LedControl L = LedControl (12, 11, 10);
// hier definieren wir die Potentiometer
const int jar = 0;
konstant int pot2 = 1;
// hier stellen wir sicher, dass wir die Werte des Potentiometers speichern können
int potwert;
int potwert2;
void setup () {
// hier setzen wir die LED-Matrix, indem wir sie ausschalten, dann die Intensität anpassen und den Speicher löschen
L. Shutdown (0, falsch);
L.setIntensity (0, 4);
L.clearDisplay (0);
}
void loop () {
// hier sagen wir, dass der Arduino die analogen Ports für Werte lesen sollte
potvalue = analogRead (Topf);
// hier definieren wir die Werte, die der Topfzähler anzeigen kann
potvalue = map (potvalue, 0, 1000, 0, 7);
potvalue2 = analogRead (pot2);
potvalue2 = map (potvalue2, 0, 1000, 0, 7);
// hier prüfen wir, ob beide Werte gleich 0 sind, wenn ja Licht 0,0 aufleuchtet
// Wenn also 1 und 2 gleich 0 sind, wird 0,0 eingeschaltet
if (potvalue == 0 && potvalue2 == 0) {
int-Reihe = 0;
int spalte = 0;
L.setLed (0, row, col, true);
}
// hier schauen wir, ob einer dieser Werte nicht 0 ist, wenn true 0,0 ausgeht
// Wir wiederholen diesen Vorgang die ganze Zeit, bis alle Koordinaten definiert sind
// Was hier steht, ist, wenn 1 oder 2 nicht gleich 0 ist, dann geht 0,0 aus
if (potvalue! = 0 || potvalue2! = 0) {
int-Reihe = 0;
int spalte = 0;
L.setLed (0, row, col, false);
}
if (potvalue == 1 && potvalue2 == 0) {
int-Reihe = 1;
int spalte = 0;
L.setLed (0, row, col, true);
}
if (potvalue! = 1 || potvalue2! = 0) {
int-Reihe = 1;
int spalte = 0;
L.setLed (0, row, col, false);
}
if (potvalue == 2 && potvalue2 == 0) {
int-Reihe = 2;
int spalte = 0;
L.setLed (0, row, col, true);
}
if (potvalue! = 2 || potvalue2! = 0) {
int-Reihe = 2;
int spalte = 0;
L.setLed (0, row, col, false);
}
if (potvalue == 3 && potvalue2 == 0) {
int-Reihe = 3;
int spalte = 0;
L.setLed (0, row, col, true);
}
if (potvalue! = 3 || potvalue2! = 0) {
int-Reihe = 3;
int spalte = 0;
L.setLed (0, row, col, false);
}
if (potvalue == 4 && potvalue2 == 0) {
int-Reihe = 4;
int spalte = 0;
L.setLed (0, row, col, true);
}
if (potvalue! = 4 || potvalue2! = 0) {
int-Reihe = 4;
int spalte = 0;
L.setLed (0, row, col, false);
}
if (potvalue == 5 && potvalue2 == 0) {
int-Reihe = 5;
int spalte = 0;
L.setLed (0, row, col, true);
}
if (potvalue! = 5 || potvalue2! = 0) {
int-Reihe = 5;
int spalte = 0;
L.setLed (0, row, col, false);
}
if (potvalue == 6 && potvalue2 == 0) {
int-Reihe = 6;
int spalte = 0;
L.setLed (0, row, col, true);
}
if (potvalue! = 6 || potvalue2! = 0) {
int-Reihe = 6;
int spalte = 0;
L.setLed (0, row, col, false);
}
if (potvalue == 7 && potvalue2 == 0) {
int-Reihe = 7;
int spalte = 0;
L.setLed (0, row, col, true);
}
if (potvalue! = 7 || potvalue2! = 0) {
int-Reihe = 7;
int spalte = 0;
L.setLed (0, row, col, false);
}
if (potvalue == 0 && potvalue2 == 1) {
int-Reihe = 0;
int spalte = 1;
L.setLed (0, row, col, true);
}
if (potvalue! = 0 || potvalue2! = 1) {
int-Reihe = 0;
int spalte = 1;
L.setLed (0, row, col, false);
}
if (potvalue == 1 && potvalue2 == 1) {
int-Reihe = 1;
int spalte = 1;
L.setLed (0, row, col, true);
}
if (potvalue! = 1 || potvalue2! = 1) {
int-Reihe = 1;
int spalte = 1;
L.setLed (0, row, col, false);
}
if (potvalue == 2 && potvalue2 == 1) {
int-Reihe = 2;
int spalte = 1;
L.setLed (0, row, col, true);
}
if (potvalue! = 2 || potvalue2! = 1) {
int-Reihe = 2;
int spalte = 1;
L.setLed (0, row, col, false);
}
if (potvalue == 3 && potvalue2 == 1) {
int-Reihe = 3;
int spalte = 1;
L.setLed (0, row, col, true);
}
if (potvalue! = 3 || potvalue2! = 1) {
int-Reihe = 3;
int spalte = 1;
L.setLed (0, row, col, false);
}
if (potvalue == 4 && potvalue2 == 1) {
int-Reihe = 4;
int spalte = 1;
L.setLed (0, row, col, true);
}
if (potvalue! = 4 || potvalue2! = 1) {
int-Reihe = 4;
int spalte = 1;
L.setLed (0, row, col, false);
}
if (potvalue == 5 && potvalue2 == 1) {
int-Reihe = 5;
int spalte = 1;
L.setLed (0, row, col, true);
}
if (potvalue! = 5 || potvalue2! = 1) {
int-Reihe = 5;
int spalte = 1;
L.setLed (0, row, col, false);
}
if (potvalue == 6 && potvalue2 == 1) {
int-Reihe = 6;
int spalte = 1;
L.setLed (0, row, col, true);
}
if (potvalue! = 6 || potvalue2! = 1) {
int-Reihe = 6;
int spalte = 1;
L.setLed (0, row, col, false);
}
if (potvalue == 7 && potvalue2 == 1) {
int-Reihe = 7;
int spalte = 1;
L.setLed (0, row, col, true);
}
if (potvalue! = 7 || potvalue2! = 1) {
int-Reihe = 7;
int spalte = 1;
L.setLed (0, row, col, false);
}
if (potvalue == 0 && potvalue2 == 2) {
int-Reihe = 0;
int spalte = 2;
L.setLed (0, row, col, true);
}
if (potvalue! = 0 || potvalue2! = 2) {
int-Reihe = 0;
int spalte = 2;
L.setLed (0, row, col, false);
}
if (potvalue == 1 && potvalue2 == 2) {
int-Reihe = 1;
int spalte = 2;
L.setLed (0, row, col, true);
}
if (potvalue! = 1 || potvalue2! = 2) {
int-Reihe = 1;
int spalte = 2;
L.setLed (0, row, col, false);
}
if (potvalue == 2 && potvalue2 == 2) {
int-Reihe = 2;
int spalte = 2;
L.setLed (0, row, col, true);
}
if (potvalue! = 2 || potvalue2! = 2) {
int-Reihe = 2;
int spalte = 2;
L.setLed (0, row, col, false);
}
if (potvalue == 3 && potvalue2 == 2) {
int-Reihe = 3;
int spalte = 2;
L.setLed (0, row, col, true);
}
if (potvalue! = 3 || potvalue2! = 2) {
int-Reihe = 3;
int spalte = 2;
L.setLed (0, row, col, false);
}
if (potvalue == 4 && potvalue2 == 2) {
int-Reihe = 4;
int spalte = 2;
L.setLed (0, row, col, true);
}
if (potvalue! = 4 || potvalue2! = 2) {
int-Reihe = 4;
int spalte = 2;
L.setLed (0, row, col, false);
}
if (potvalue == 5 && potvalue2 == 2) {
int-Reihe = 5;
int spalte = 2;
L.setLed (0, row, col, true);
}
if (potvalue! = 5 || potvalue2! = 2) {
int-Reihe = 5;
int spalte = 2;
L.setLed (0, row, col, false);
}
if (potvalue == 6 && potvalue2 == 2) {
int-Reihe = 6;
int spalte = 2;
L.setLed (0, row, col, true);
}
if (potvalue! = 6 || potvalue2! = 2) {
int-Reihe = 6;
int spalte = 2;
L.setLed (0, row, col, false);
}
if (potvalue == 7 && potvalue2 == 2) {
int-Reihe = 7;
int spalte = 2;
L.setLed (0, row, col, true);
}
if (potvalue! = 7 || potvalue2! = 2) {
int-Reihe = 7;
int spalte = 2;
L.setLed (0, row, col, false);
}
if (potvalue == 0 && potvalue2 == 3) {
int-Reihe = 0;
int spalte = 3;
L.setLed (0, row, col, true);
}
if (potvalue! = 0 || potvalue2! = 3) {
int-Reihe = 0;
int spalte = 3;
L.setLed (0, row, col, false);
}
if (potvalue == 1 && potvalue2 == 3) {
int-Reihe = 1;
int spalte = 3;
L.setLed (0, row, col, true);
}
if (potvalue! = 1 || potvalue2! = 3) {
int-Reihe = 1;
int spalte = 3;
L.setLed (0, row, col, false);
}
if (potvalue == 2 && potvalue2 == 3) {
int-Reihe = 2;
int spalte = 3;
L.setLed (0, row, col, true);
}
if (potvalue! = 2 || potvalue2! = 3) {
int-Reihe = 2;
int spalte = 3;
L.setLed (0, row, col, false);
}
if (potvalue == 3 && potvalue2 == 3) {
int-Reihe = 3;
int spalte = 3;
L.setLed (0, row, col, true);
}
if (potvalue! = 3 || potvalue2! = 3) {
int-Reihe = 3;
int spalte = 3;
L.setLed (0, row, col, false);
}
if (potvalue == 4 && potvalue2 == 3) {
int-Reihe = 4;
int spalte = 3;
L.setLed (0, row, col, true);
}
if (potvalue! = 4 || potvalue2! = 3) {
int-Reihe = 4;
int spalte = 3;
L.setLed (0, row, col, false);
}
if (potvalue == 5 && potvalue2 == 3) {
int-Reihe = 5;
int spalte = 3;
L.setLed (0, row, col, true);
}
if (potvalue! = 5 || potvalue2! = 3) {
int-Reihe = 5;
int spalte = 3;
L.setLed (0, row, col, false);
}
if (potvalue == 6 && potvalue2 == 3) {
int-Reihe = 6;
int spalte = 3;
L.setLed (0, row, col, true);
}
if (potvalue! = 6 || potvalue2! = 3) {
int-Reihe = 6;
int spalte = 3;
L.setLed (0, row, col, false);
}
if (potvalue == 7 && potvalue2 == 3) {
int-Reihe = 7;
int spalte = 3;
L.setLed (0, row, col, true);
}
if (potvalue! = 7 || potvalue2! = 3) {
int-Reihe = 7;
int spalte = 3;
L.setLed (0, row, col, false);
}
if (potvalue == 0 && potvalue2 == 4) {
int-Reihe = 0;
int spalte = 4;
L.setLed (0, row, col, true);
}
if (potvalue! = 0 || potvalue2! = 4) {
int-Reihe = 0;
int spalte = 4;
L.setLed (0, row, col, false);
}
if (potvalue == 1 && potvalue2 == 4) {
int-Reihe = 1;
int spalte = 4;
L.setLed (0, row, col, true);
}
if (potvalue! = 1 || potvalue2! = 4) {
int-Reihe = 1;
int spalte = 4;
L.setLed (0, row, col, false);
}
if (potvalue == 2 && potvalue2 == 4) {
int-Reihe = 2;
int spalte = 4;
L.setLed (0, row, col, true);
}
if (potvalue! = 2 || potvalue2! = 4) {
int-Reihe = 2;
int spalte = 4;
L.setLed (0, row, col, false);
}
if (potvalue == 3 && potvalue2 == 4) {
int-Reihe = 3;
int spalte = 4;
L.setLed (0, row, col, true);
}
if (potvalue! = 3 || potvalue2! = 4) {
int-Reihe = 3;
int spalte = 4;
L.setLed (0, row, col, false);
}
if (potvalue == 4 && potvalue2 == 4) {
int-Reihe = 4;
int spalte = 4;
L.setLed (0, row, col, true);
}
if (potvalue! = 4 || potvalue2! = 4) {
int-Reihe = 4;
int spalte = 4;
L.setLed (0, row, col, false);
}
if (potvalue == 5 && potvalue2 == 4) {
int-Reihe = 5;
int spalte = 4;
L.setLed (0, row, col, true);
}
if (potvalue! = 5 || potvalue2! = 4) {
int-Reihe = 5;
int spalte = 4;
L.setLed (0, row, col, false);
}
if (potvalue == 6 && potvalue2 == 4) {
int-Reihe = 6;
int spalte = 4;
L.setLed (0, row, col, true);
}
if (potvalue! = 6 || potvalue2! = 4) {
int-Reihe = 6;
int spalte = 4;
L.setLed (0, row, col, false);
}
if (potvalue == 7 && potvalue2 == 4) {
int-Reihe = 7;
int spalte = 4;
L.setLed (0, row, col, true);
}
if (potvalue! = 7 || potvalue2! = 4) {
int-Reihe = 7;
int spalte = 4;
L.setLed (0, row, col, false);
}
if (potvalue == 0 && potvalue2 == 5) {
int-Reihe = 0;
int spalte = 5;
L.setLed (0, row, col, true);
}
if (potvalue! = 0 || potvalue2! = 5) {
int-Reihe = 0;
int spalte = 5;
L.setLed (0, row, col, false);
}
if (potvalue == 1 && potvalue2 == 5) {
int-Reihe = 1;
int spalte = 5;
L.setLed (0, row, col, true);
}
if (potvalue! = 1 || potvalue2! = 5) {
int-Reihe = 1;
int spalte = 5;
L.setLed (0, row, col, false);
}
if (potvalue == 2 && potvalue2 == 5) {
int-Reihe = 2;
int spalte = 5;
L.setLed (0, row, col, true);
}
if (potvalue! = 2 || potvalue2! = 5) {
int-Reihe = 2;
int spalte = 5;
L.setLed (0, row, col, false);
}
if (potvalue == 3 && potvalue2 == 5) {
int-Reihe = 3;
int spalte = 5;
L.setLed (0, row, col, true);
}
if (potvalue! = 3 || potvalue2! = 5) {
int-Reihe = 3;
int spalte = 5;
L.setLed (0, row, col, false);
}
if (potvalue == 4 && potvalue2 == 5) {
int-Reihe = 4;
int spalte = 5;
L.setLed (0, row, col, true);
}
if (potvalue! = 4 || potvalue2! = 5) {
int-Reihe = 4;
int spalte = 5;
L.setLed (0, row, col, false);
}
if (potvalue == 5 && potvalue2 == 5) {
int-Reihe = 5;
int spalte = 5;
L.setLed (0, row, col, true);
}
if (potvalue! = 5 || potvalue2! = 5) {
int-Reihe = 5;
int spalte = 5;
L.setLed (0, row, col, false);
}
if (potvalue == 6 && potvalue2 == 5) {
int-Reihe = 6;
int spalte = 5;
L.setLed (0, row, col, true);
}
if (potvalue! = 6 || potvalue2! = 5) {
int-Reihe = 6;
int spalte = 5;
L.setLed (0, row, col, false);
}
if (potvalue == 7 && potvalue2 == 5) {
int-Reihe = 7;
int spalte = 5;
L.setLed (0, row, col, true);
}
if (potvalue! = 7 || potvalue2! = 5) {
int-Reihe = 7;
int spalte = 5;
L.setLed (0, row, col, false);
}
if (potvalue == 0 && potvalue2 == 6) {
int-Reihe = 0;
int spalte = 6;
L.setLed (0, row, col, true);
}
if (potvalue! = 0 || potvalue2! = 6) {
int-Reihe = 0;
int spalte = 6;
L.setLed (0, row, col, false);
}
if (potvalue == 1 && potvalue2 == 6) {
int-Reihe = 1;
int spalte = 6;
L.setLed (0, row, col, true);
}
if (potvalue! = 1 || potvalue2! = 6) {
int-Reihe = 1;
int spalte = 6;
L.setLed (0, row, col, false);
}
if (potvalue == 2 && potvalue2 == 6) {
int-Reihe = 2;
int spalte = 6;
L.setLed (0, row, col, true);
}
if (potvalue! = 2 || potvalue2! = 6) {
int-Reihe = 2;
int spalte = 6;
L.setLed (0, row, col, false);
}
if (potvalue == 3 && potvalue2 == 6) {
int-Reihe = 3;
int spalte = 6;
L.setLed (0, row, col, true);
}
if (potvalue! = 3 || potvalue2! = 6) {
int-Reihe = 3;
int spalte = 6;
L.setLed (0, row, col, false);
}
if (potvalue == 4 && potvalue2 == 6) {
int-Reihe = 4;
int spalte = 6;
L.setLed (0, row, col, true);
}
if (potvalue! = 4 || potvalue2! = 6) {
int-Reihe = 4;
int spalte = 6;
L.setLed (0, row, col, false);
}
if (potvalue == 5 && potvalue2 == 6) {
int-Reihe = 5;
int spalte = 6;
L.setLed (0, row, col, true);
}
if (potvalue! = 5 || potvalue2! = 6) {
int-Reihe = 5;
int spalte = 6;
L.setLed (0, row, col, false);
}
if (potvalue == 6 && potvalue2 == 6) {
int-Reihe = 6;
int spalte = 6;
L.setLed (0, row, col, true);
}
if (potvalue! = 6 || potvalue2! = 6) {
int-Reihe = 6;
int spalte = 6;
L.setLed (0, row, col, false);
}
if (potvalue == 7 && potvalue2 == 6) {
int-Reihe = 7;
int spalte = 6;
L.setLed (0, row, col, true);
}
if (potvalue! = 7 || potvalue2! = 6) {
int-Reihe = 7;
int spalte = 6;
L.setLed (0, row, col, false);
}
if (potvalue == 0 && potvalue2 == 7) {
int-Reihe = 0;
int spalte = 7;
L.setLed (0, row, col, true);
}
if (potvalue! = 0 || potvalue2! = 7) {
int-Reihe = 0;
int spalte = 7;
L.setLed (0, row, col, false);
}
if (potvalue == 1 && potvalue2 == 7) {
int-Reihe = 1;
int spalte = 7;
L.setLed (0, row, col, true);
}
if (potvalue! = 1 || potvalue2! = 7) {
int-Reihe = 1;
int spalte = 7;
L.setLed (0, row, col, false);
}
if (potvalue == 2 && potvalue2 == 7) {
int-Reihe = 2;
int spalte = 7;
L.setLed (0, row, col, true);
}
if (potvalue! = 2 || potvalue2! = 7) {
int-Reihe = 2;
int spalte = 7;
L.setLed (0, row, col, false);
}
if (potvalue == 3 && potvalue2 == 7) {
int-Reihe = 3;
int spalte = 7;
L.setLed (0, row, col, true);
}
if (potvalue! = 3 || potvalue2! = 7) {
int-Reihe = 3;
int spalte = 7;
L.setLed (0, row, col, false);
}
if (potvalue == 4 && potvalue2 == 7) {
int-Reihe = 4;
int spalte = 7;
L.setLed (0, row, col, true);
}
if (potvalue! = 4 || potvalue2! = 7) {
int-Reihe = 4;
int spalte = 7;
L.setLed (0, row, col, false);
}
if (potvalue == 5 && potvalue2 == 7) {
int-Reihe = 5;
int spalte = 7;
L.setLed (0, row, col, true);
}
if (potvalue! = 5 || potvalue2! = 7) {
int-Reihe = 5;
int spalte = 7;
L.setLed (0, row, col, false);
}
if (potvalue == 6 && potvalue2 == 7) {
int-Reihe = 6;
int spalte = 7;
L.setLed (0, row, col, true);
}
if (potvalue! = 6 || potvalue2! = 7) {
int-Reihe = 6;
int spalte = 7;
L.setLed (0, row, col, false);
}
if (potvalue == 7 && potvalue2 == 7) {
int-Reihe = 7;
int spalte = 7;
L.setLed (0, row, col, true);
}
if (potvalue! = 7 || potvalue2! = 7) {
int-Reihe = 7;
int spalte = 7;
L.setLed (0, row, col, false);
}
}
Hallo, woher kommt ledcontrol.h? Ich bin ein Anfänger 😉
Vielen Dank im Voraus!
Öffnen Sie die arduino IDE-Software und klicken Sie auf Sketch. Dann Bibliothek verwenden. Verwalten Sie dann Bibliotheken. Dann öffnet er den Bibliotheksmanager. Dann suchen Sie oben nach: LedControl. Wählen Sie das oberste aus. Passt auf! Es MUSS von Eberhard Fahle gemacht worden sein.
Gern geschehen! 😉