Niveau – beginner / gemiddeld
Tijdsduur – 45 / 60 Min
Kosten – €12.65 euro zonder Arduino met €36.51 euro

Bij dit gemiddelde project laat ik zien hoe je een balletje kan besturen op een 8×8 led matrix.

Met dit project kan je een balletje met twee potentiometers over X en de Y as van de matrix bewegen. In dit project leer je hoe je een led matrix kan gebruiken en hoe je de waardes van een potentiometer kan aflezen.

Stap 2: Bouwen en Bedraden

Nu je alle onderdelen hebt kan je beginnen met het aansluiten van de onderdelen.

Als eerste ga je van de 5V op de UNO naar de plus op het breadboard en van de GND naar de min op het breadboard. Zodra je dat hebt gedaan doe je de potentiometers in het breadboard. Dan neem je de meest linker pin van beide potentiometers en die doe je in de plus, de meest rechter in de min en de middelste van een gaat in de A0 en de bij de andere in de A1.

Nu gaan we de led matrix aansluiten de led matrix doe je ook in het breadboard met de chip onder. De VCC van de led matrix gaat naar de plus en de GND gaat naar de min. We gaan nu als laatste de I/O pinnen op de drie overige pinnen op de matrix aansluiten. De DIN gaat naar pin 12, de CS gaat naar pin 10 en de CLK gaat naar pin 11.

Stap 3: Programmeren

Nu je alles op de goede manier hebt aangesloten kan je beginnen met programmeren.

Het is een hele hoop maar het is constant het zelfde meet maar een paar waardes die veranderen.

De code nu is gemaakt voor een led matrix die alleen maar een X en Y as heeft. Maar als je dit wil doen met een matrix dat ook een Z as heeft moet je een extra potentiometer toevoegen en de code zo aanpassen dat de waardes daarvan kunnen worden afglezen.

#include
//hier geven we de LED matrix een naam en de I/O pinnen die hij kan besturen 
LedControl L = LedControl(12, 11, 10);
//hier defineren we de potentiometers
const int pot = 0;
const int pot2 = 1;
//hier zorgen we ervoor dat we de waardes van de potentiometer kunnen opslaan
int potvalue;
int potvalue2;

void setup(){
  //hier stellen we de led matrix in door hem uit te zetten daarna de intensiteit aan te passen en het geheugen te wissen 
  L.shutdown(0, false);
  L.setIntensity(0, 4);
  L.clearDisplay(0);
}

void loop(){
  //hier zeggen we dat de Arduino de analoge poorten moet lezen voor waardes
  potvalue = analogRead(pot);
  //hier defineren we de waardes die de pot meter aan kan geven
  potvalue = map(potvalue, 0, 1000, 0, 7);
  potvalue2 = analogRead(pot2);
  potvalue2 = map(potvalue2, 0, 1000, 0, 7);
  //hier kijken we of beide waardes gelijk zijn aan 0 zo ja lampje 0,0 gaat aan
  //wat hier dus eigenlijk staat is als 1 en 2 gelijk zijn aan 0 dan gaat 0,0 aan
  if(potvalue == 0 && potvalue2 == 0){
    int row = 0;
    int col = 0;
    L.setLed(0, row, col, true);
  }
  //hier kijken we of een van die waardes niet 0 is als dat waar is gaat 0,0 uit
  //dit proces blijven we de hele tijd herhalen totdat alle coördinaten zijn gedefinieerd 
  //wat hier staat is als 1 of 2 niet gelijk is aan 0 dan gaat 0,0 uit
  if(potvalue != 0 || potvalue2 != 0){
    int row = 0;
    int col = 0;
    L.setLed(0, row, col, false);
  }
  if(potvalue == 1 && potvalue2 == 0){
    int row = 1;
    int col = 0;
    L.setLed(0, row, col, true);
  }
  if(potvalue != 1 || potvalue2 != 0){
    int row = 1;
    int col = 0;
    L.setLed(0, row, col, false);
  }
    if(potvalue == 2 && potvalue2 == 0){
    int row = 2;
    int col = 0;
    L.setLed(0, row, col, true);
  }
  if(potvalue != 2 || potvalue2 != 0){
    int row = 2;
    int col = 0;
    L.setLed(0, row, col, false);
  }
    if(potvalue == 3 && potvalue2 == 0){
    int row = 3;
    int col = 0;
    L.setLed(0, row, col, true);
  }
  if(potvalue != 3 || potvalue2 != 0){
    int row = 3;
    int col = 0;
    L.setLed(0, row, col, false);
  }
    if(potvalue == 4 && potvalue2 == 0){
    int row = 4;
    int col = 0;
    L.setLed(0, row, col, true);
  }
  if(potvalue != 4 || potvalue2 != 0){
    int row = 4;
    int col = 0;
    L.setLed(0, row, col, false);
  }
    if(potvalue == 5 && potvalue2 == 0){
    int row = 5;
    int col = 0;
    L.setLed(0, row, col, true);
  }
  if(potvalue != 5 || potvalue2 != 0){
    int row = 5;
    int col = 0;
    L.setLed(0, row, col, false);
  }
    if(potvalue == 6 && potvalue2 == 0){
    int row = 6;
    int col = 0;
    L.setLed(0, row, col, true);
  }
  if(potvalue != 6 || potvalue2 != 0){
    int row = 6;
    int col = 0;
    L.setLed(0, row, col, false);
  }
    if(potvalue == 7 && potvalue2 == 0){
    int row = 7;
    int col = 0;
    L.setLed(0, row, col, true);
  }
  if(potvalue != 7 || potvalue2 != 0){
    int row = 7;
    int col = 0;
    L.setLed(0, row, col, false);
  }
  if(potvalue == 0 && potvalue2 == 1){
    int row = 0;
    int col = 1;
    L.setLed(0, row, col, true);
  }
  if(potvalue != 0 || potvalue2 != 1){
    int row = 0;
    int col = 1;
    L.setLed(0, row, col, false);
  }
  if(potvalue == 1 && potvalue2 == 1){
    int row = 1;
    int col = 1;
    L.setLed(0, row, col, true);
  }
  if(potvalue != 1 || potvalue2 != 1){
    int row = 1;
    int col = 1;
    L.setLed(0, row, col, false);
  }
    if(potvalue == 2 && potvalue2 == 1){
    int row = 2;
    int col = 1;
    L.setLed(0, row, col, true);
  }
  if(potvalue != 2 || potvalue2 != 1){
    int row = 2;
    int col = 1;
    L.setLed(0, row, col, false);
  }
    if(potvalue == 3 && potvalue2 == 1){
    int row = 3;
    int col = 1;
    L.setLed(0, row, col, true);
  }
  if(potvalue != 3 || potvalue2 != 1){
    int row = 3;
    int col = 1;
    L.setLed(0, row, col, false);
  }
    if(potvalue == 4 && potvalue2 == 1){
    int row = 4;
    int col = 1;
    L.setLed(0, row, col, true);
  }
  if(potvalue != 4 || potvalue2 != 1){
    int row = 4;
    int col = 1;
    L.setLed(0, row, col, false);
  }
    if(potvalue == 5 && potvalue2 == 1){
    int row = 5;
    int col = 1;
    L.setLed(0, row, col, true);
  }
  if(potvalue != 5 || potvalue2 != 1){
    int row = 5;
    int col = 1;
    L.setLed(0, row, col, false);
  }
    if(potvalue == 6 && potvalue2 == 1){
    int row = 6;
    int col = 1;
    L.setLed(0, row, col, true);
  }
  if(potvalue != 6 || potvalue2 != 1){
    int row = 6;
    int col = 1;
    L.setLed(0, row, col, false);
  }
    if(potvalue == 7 && potvalue2 == 1){
    int row = 7;
    int col = 1;
    L.setLed(0, row, col, true);
  }
  if(potvalue != 7 || potvalue2 != 1){
    int row = 7;
    int col = 1;
    L.setLed(0, row, col, false);
  }
  if(potvalue == 0 && potvalue2 == 2){
    int row = 0;
    int col = 2;
    L.setLed(0, row, col, true);
  }
  if(potvalue != 0 || potvalue2 != 2){
    int row = 0;
    int col = 2;
    L.setLed(0, row, col, false);
  }
  if(potvalue == 1 && potvalue2 == 2){
    int row = 1;
    int col = 2;
    L.setLed(0, row, col, true);
  }
  if(potvalue != 1 || potvalue2 != 2){
    int row = 1;
    int col = 2;
    L.setLed(0, row, col, false);
  }
    if(potvalue == 2 && potvalue2 == 2){
    int row = 2;
    int col = 2;
    L.setLed(0, row, col, true);
  }
  if(potvalue != 2 || potvalue2 != 2){
    int row = 2;
    int col = 2;
    L.setLed(0, row, col, false);
  }
    if(potvalue == 3 && potvalue2 == 2){
    int row = 3;
    int col = 2;
    L.setLed(0, row, col, true);
  }
  if(potvalue != 3 || potvalue2 != 2){
    int row = 3;
    int col = 2;
    L.setLed(0, row, col, false);
  }
    if(potvalue == 4 && potvalue2 == 2){
    int row = 4;
    int col = 2;
    L.setLed(0, row, col, true);
  }
  if(potvalue != 4 || potvalue2 != 2){
    int row = 4;
    int col = 2;
    L.setLed(0, row, col, false);
  }
    if(potvalue == 5 && potvalue2 == 2){
    int row = 5;
    int col = 2;
    L.setLed(0, row, col, true);
  }
  if(potvalue != 5 || potvalue2 != 2){
    int row = 5;
    int col = 2;
    L.setLed(0, row, col, false);
  }
    if(potvalue == 6 && potvalue2 == 2){
    int row = 6;
    int col = 2;
    L.setLed(0, row, col, true);
  }
  if(potvalue != 6 || potvalue2 != 2){
    int row = 6;
    int col = 2;
    L.setLed(0, row, col, false);
  }
    if(potvalue == 7 && potvalue2 == 2){
    int row = 7;
    int col = 2;
    L.setLed(0, row, col, true);
  }
  if(potvalue != 7 || potvalue2 != 2){
    int row = 7;
    int col = 2;
    L.setLed(0, row, col, false);
  }
  if(potvalue == 0 && potvalue2 == 3){
    int row = 0;
    int col = 3;
    L.setLed(0, row, col, true);
  }
  if(potvalue != 0 || potvalue2 != 3){
    int row = 0;
    int col = 3;
    L.setLed(0, row, col, false);
  }
  if(potvalue == 1 && potvalue2 == 3){
    int row = 1;
    int col = 3;
    L.setLed(0, row, col, true);
  }
  if(potvalue != 1 || potvalue2 != 3){
    int row = 1;
    int col = 3;
    L.setLed(0, row, col, false);
  }
    if(potvalue == 2 && potvalue2 == 3){
    int row = 2;
    int col = 3;
    L.setLed(0, row, col, true);
  }
  if(potvalue != 2 || potvalue2 != 3){
    int row = 2;
    int col = 3;
    L.setLed(0, row, col, false);
  }
    if(potvalue == 3 && potvalue2 == 3){
    int row = 3;
    int col = 3;
    L.setLed(0, row, col, true);
  }
  if(potvalue != 3 || potvalue2 != 3){
    int row = 3;
    int col = 3;
    L.setLed(0, row, col, false);
  }
    if(potvalue == 4 && potvalue2 == 3){
    int row = 4;
    int col = 3;
    L.setLed(0, row, col, true);
  }
  if(potvalue != 4 || potvalue2 != 3){
    int row = 4;
    int col = 3;
    L.setLed(0, row, col, false);
  }
    if(potvalue == 5 && potvalue2 == 3){
    int row = 5;
    int col = 3;
    L.setLed(0, row, col, true);
  }
  if(potvalue != 5 || potvalue2 != 3){
    int row = 5;
    int col = 3;
    L.setLed(0, row, col, false);
  }
    if(potvalue == 6 && potvalue2 == 3){
    int row = 6;
    int col = 3;
    L.setLed(0, row, col, true);
  }
  if(potvalue != 6 || potvalue2 != 3){
    int row = 6;
    int col = 3;
    L.setLed(0, row, col, false);
  }
    if(potvalue == 7 && potvalue2 == 3){
    int row = 7;
    int col = 3;
    L.setLed(0, row, col, true);
  }
  if(potvalue != 7 || potvalue2 != 3){
    int row = 7;
    int col = 3;
    L.setLed(0, row, col, false);
  }
  if(potvalue == 0 && potvalue2 == 4){
    int row = 0;
    int col = 4;
    L.setLed(0, row, col, true);
  }
  if(potvalue != 0 || potvalue2 != 4){
    int row = 0;
    int col = 4;
    L.setLed(0, row, col, false);
  }
  if(potvalue == 1 && potvalue2 == 4){
    int row = 1;
    int col = 4;
    L.setLed(0, row, col, true);
  }
  if(potvalue != 1 || potvalue2 != 4){
    int row = 1;
    int col = 4;
    L.setLed(0, row, col, false);
  }
    if(potvalue == 2 && potvalue2 == 4){
    int row = 2;
    int col = 4;
    L.setLed(0, row, col, true);
  }
  if(potvalue != 2 || potvalue2 != 4){
    int row = 2;
    int col = 4;
    L.setLed(0, row, col, false);
  }
    if(potvalue == 3 && potvalue2 == 4){
    int row = 3;
    int col = 4;
    L.setLed(0, row, col, true);
  }
  if(potvalue != 3 || potvalue2 != 4){
    int row = 3;
    int col = 4;
    L.setLed(0, row, col, false);
  }
    if(potvalue == 4 && potvalue2 == 4){
    int row = 4;
    int col = 4;
    L.setLed(0, row, col, true);
  }
  if(potvalue != 4 || potvalue2 != 4){
    int row = 4;
    int col = 4;
    L.setLed(0, row, col, false);
  }
    if(potvalue == 5 && potvalue2 == 4){
    int row = 5;
    int col = 4;
    L.setLed(0, row, col, true);
  }
  if(potvalue != 5 || potvalue2 != 4){
    int row = 5;
    int col = 4;
    L.setLed(0, row, col, false);
  }
    if(potvalue == 6 && potvalue2 == 4){
    int row = 6;
    int col = 4;
    L.setLed(0, row, col, true);
  }
  if(potvalue != 6 || potvalue2 != 4){
    int row = 6;
    int col = 4;
    L.setLed(0, row, col, false);
  }
    if(potvalue == 7 && potvalue2 == 4){
    int row = 7;
    int col = 4;
    L.setLed(0, row, col, true);
  }
  if(potvalue != 7 || potvalue2 != 4){
    int row = 7;
    int col = 4;
    L.setLed(0, row, col, false);
  }
  if(potvalue == 0 && potvalue2 == 5){
    int row = 0;
    int col = 5;
    L.setLed(0, row, col, true);
  }
  if(potvalue != 0 || potvalue2 != 5){
    int row = 0;
    int col = 5;
    L.setLed(0, row, col, false);
  }
  if(potvalue == 1 && potvalue2 == 5){
    int row = 1;
    int col = 5;
    L.setLed(0, row, col, true);
  }
  if(potvalue != 1 || potvalue2 != 5){
    int row = 1;
    int col = 5;
    L.setLed(0, row, col, false);
  }
    if(potvalue == 2 && potvalue2 == 5){
    int row = 2;
    int col = 5;
    L.setLed(0, row, col, true);
  }
  if(potvalue != 2 || potvalue2 != 5){
    int row = 2;
    int col = 5;
    L.setLed(0, row, col, false);
  }
    if(potvalue == 3 && potvalue2 == 5){
    int row = 3;
    int col = 5;
    L.setLed(0, row, col, true);
  }
  if(potvalue != 3 || potvalue2 != 5){
    int row = 3;
    int col = 5;
    L.setLed(0, row, col, false);
  }
    if(potvalue == 4 && potvalue2 == 5){
    int row = 4;
    int col = 5;
    L.setLed(0, row, col, true);
  }
  if(potvalue != 4 || potvalue2 != 5){
    int row = 4;
    int col = 5;
    L.setLed(0, row, col, false);
  }
    if(potvalue == 5 && potvalue2 == 5){
    int row = 5;
    int col = 5;
    L.setLed(0, row, col, true);
  }
  if(potvalue != 5 || potvalue2 != 5){
    int row = 5;
    int col = 5;
    L.setLed(0, row, col, false);
  }
    if(potvalue == 6 && potvalue2 == 5){
    int row = 6;
    int col = 5;
    L.setLed(0, row, col, true);
  }
  if(potvalue != 6 || potvalue2 != 5){
    int row = 6;
    int col = 5;
    L.setLed(0, row, col, false);
  }
    if(potvalue == 7 && potvalue2 == 5){
    int row = 7;
    int col = 5;
    L.setLed(0, row, col, true);
  }
  if(potvalue != 7 || potvalue2 != 5){
    int row = 7;
    int col = 5;
    L.setLed(0, row, col, false);
  }
  if(potvalue == 0 && potvalue2 == 6){
    int row = 0;
    int col = 6;
    L.setLed(0, row, col, true);
  }
  if(potvalue != 0 || potvalue2 != 6){
    int row = 0;
    int col = 6;
    L.setLed(0, row, col, false);
  }
  if(potvalue == 1 && potvalue2 == 6){
    int row = 1;
    int col = 6;
    L.setLed(0, row, col, true);
  }
  if(potvalue != 1 || potvalue2 != 6){
    int row = 1;
    int col = 6;
    L.setLed(0, row, col, false);
  }
    if(potvalue == 2 && potvalue2 == 6){
    int row = 2;
    int col = 6;
    L.setLed(0, row, col, true);
  }
  if(potvalue != 2 || potvalue2 != 6){
    int row = 2;
    int col = 6;
    L.setLed(0, row, col, false);
  }
    if(potvalue == 3 && potvalue2 == 6){
    int row = 3;
    int col = 6;
    L.setLed(0, row, col, true);
  }
  if(potvalue != 3 || potvalue2 != 6){
    int row = 3;
    int col = 6;
    L.setLed(0, row, col, false);
  }
    if(potvalue == 4 && potvalue2 == 6){
    int row = 4;
    int col = 6;
    L.setLed(0, row, col, true);
  }
  if(potvalue != 4 || potvalue2 != 6){
    int row = 4;
    int col = 6;
    L.setLed(0, row, col, false);
  }
    if(potvalue == 5 && potvalue2 == 6){
    int row = 5;
    int col = 6;
    L.setLed(0, row, col, true);
  }
  if(potvalue != 5 || potvalue2 != 6){
    int row = 5;
    int col = 6;
    L.setLed(0, row, col, false);
  }
    if(potvalue == 6 && potvalue2 == 6){
    int row = 6;
    int col = 6;
    L.setLed(0, row, col, true);
  }
  if(potvalue != 6 || potvalue2 != 6){
    int row = 6;
    int col = 6;
    L.setLed(0, row, col, false);
  }
    if(potvalue == 7 && potvalue2 == 6){
    int row = 7;
    int col = 6;
    L.setLed(0, row, col, true);
  }
  if(potvalue != 7 || potvalue2 != 6){
    int row = 7;
    int col = 6;
    L.setLed(0, row, col, false);
  }
  if(potvalue == 0 && potvalue2 == 7){
    int row = 0;
    int col = 7;
    L.setLed(0, row, col, true);
  }
  if(potvalue != 0 || potvalue2 != 7){
    int row = 0;
    int col = 7;
    L.setLed(0, row, col, false);
  }
  if(potvalue == 1 && potvalue2 == 7){
    int row = 1;
    int col = 7;
    L.setLed(0, row, col, true);
  }
  if(potvalue != 1 || potvalue2 != 7){
    int row = 1;
    int col = 7;
    L.setLed(0, row, col, false);
  }
    if(potvalue == 2 && potvalue2 == 7){
    int row = 2;
    int col = 7;
    L.setLed(0, row, col, true);
  }
  if(potvalue != 2 || potvalue2 != 7){
    int row = 2;
    int col = 7;
    L.setLed(0, row, col, false);
  }
    if(potvalue == 3 && potvalue2 == 7){
    int row = 3;
    int col = 7;
    L.setLed(0, row, col, true);
  }
  if(potvalue != 3 || potvalue2 != 7){
    int row = 3;
    int col = 7;
    L.setLed(0, row, col, false);
  }
    if(potvalue == 4 && potvalue2 == 7){
    int row = 4;
    int col = 7;
    L.setLed(0, row, col, true);
  }
  if(potvalue != 4 || potvalue2 != 7){
    int row = 4;
    int col = 7;
    L.setLed(0, row, col, false);
  }
    if(potvalue == 5 && potvalue2 == 7){
    int row = 5;
    int col = 7;
    L.setLed(0, row, col, true);
  }
  if(potvalue != 5 || potvalue2 != 7){
    int row = 5;
    int col = 7;
    L.setLed(0, row, col, false);
  }
    if(potvalue == 6 && potvalue2 == 7){
    int row = 6;
    int col = 7;
    L.setLed(0, row, col, true);
  }
  if(potvalue != 6 || potvalue2 != 7){
    int row = 6;
    int col = 7;
    L.setLed(0, row, col, false);
  }
    if(potvalue == 7 && potvalue2 == 7){
    int row = 7;
    int col = 7;
    L.setLed(0, row, col, true);
  }
  if(potvalue != 7 || potvalue2 != 7){
    int row = 7;
    int col = 7;
    L.setLed(0, row, col, false);
  }
}