Gratis verzending vanaf €74,95 NL (€99,95 BE/DE)

Voor 16:00 besteld = morgen in huis

Express voor 13:00 besteld = vanavond in huis*

14 dagen gratis terugsturen*


Land

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

Met de twee potentiometers kan je het balletje over de X en Y as van de matrix laten bewegen. 

In dit project leer je hoe je een led matrix kan gebruiken en hoe je de waardes van een potentiometer kan aflezen.

  • Niveau – Beginner / Gemiddeld 40% 40%
  • Tijdsduur – 45 / 60 Min 60% 60%
  • Kosten – €36,51 euro compleet 30% 30%

Stap 1: Benodigdheden

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 zet je de potentiometers op het breadboard. Dan neem je de meest linker pin van beide potentiometers en sluit je aan op de plus, de meest rechter in de min en de middelste van een potentiometer sluit je aan op de A0 en bij de andere in de A1. Nu gaan we de led matrix aansluiten, de led metrix zet je in het breadboard met de chip aan de onderkant. De VCC van de led matrix gaat naar de plus en de GND gaat naar de min. Dan sluiten we de I/O pinnen aan op de drie overige pinnen op de matrix. De DIN gaat naar pin 12, de CS  naar pin 10 en de CLK naar pin 11.

Stap 3: Programmeren

 

Als alles correct is aangesloten kan je beginnen met het programma schrijven.

Het is een redelijk groot programma maar is voornamelijk constant met maar een paar waardes die veranderen.

Deze code is nu gemaakt voor een led matrix die alleen maar een X en Y as heeft.

Als je ook een Z as wil gebruiken moet je een extra potentiometer aansluiten en vervolgens de code aanpassen zodat de waardes gelezen kunnen worden.

 De onderstaande code kan je overnemen, maar we raden het aan om het zelf te typen aangezien je hier meer van leert.

#include LedControl.h

//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);

  }

}

De waardering van www.elektronicavoorjou.nl bij WebwinkelKeur Reviews is 9.3/10 gebaseerd op 4782 reviews.