ArduinoBlokje om

De basis van dit project is de 8x8 LED Matrix uit het vorig project. Daar liepen de LEDs in mooie lijntjes over het scherm. Hier gaan we het iets intelligenter maken en laten we de LEDjes een vierkantje lopen.



ArduinoFritz

Zie beschrijving in het project 8x8 LED Matrix



ArduinoSketch
/*
8x8 matrix

www.punthooft.nl
*/

#define ROW_1 2
#define ROW_2 3
#define ROW_3 4
#define ROW_4 5
#define ROW_5 6
#define ROW_6 7
#define ROW_7 8
#define ROW_8 9

#define COL_1 10
#define COL_2 11
#define COL_3 12
#define COL_4 13
#define COL_5 A0
#define COL_6 A1
#define COL_7 A2
#define COL_8 A3

const byte rows[] = { ROW_1, ROW_2, ROW_3, ROW_4, ROW_5, ROW_6, ROW_7, ROW_8 };
const byte cols[] = { COL_1,COL_2, COL_3, COL_4, COL_5, COL_6, COL_7, COL_8 };

int delayCounter;
int direction;
int row;
int col;

void setup() {

  // Open serial port
  Serial.begin(9600);
 
  delayCounter=0;
  direction = 1;
  row=0;
  col=0;
}

void loop() {

  delayCounter++;
  delay(1);
  if (delayCounter>50) {
    delayCounter=0;

    switch(direction) {
      case 1: // to the right 
          col++;
          if(col>7) {
            col=7;
            direction=2;
          }
          break;
      case 2: // down
          row++;
          if(row>7) {
            row=7;
            direction=3;
          }
          break;
      case 3: // left 
          col--;
          if(col<0) {
            col=0;
            direction=4;
          }
          break;
      case 4: // up
          row--;
          if(row<0) {
            row=0;
            direction=1;
          }
          break;
    } 
  }

  displayAt(row,col);

}

void displayAt(int x,int y) {

  pinMode(cols[y],OUTPUT);
  pinMode(rows[x],OUTPUT);
  digitalWrite(cols[y], HIGH);
  digitalWrite(rows[x], HIGH);

  delayMicroseconds(25);
          
  digitalWrite(cols[y], LOW);
  digitalWrite(rows[x], LOW);
  pinMode(cols[y],INPUT);
  pinMode(rows[x],INPUT);
}




Copyright 2019 www.punthooft.nl
We do not collect cookies for advertisement. Your data is never send to third parties.