PUNTHOOFT
ArduinoBlokje om
De basis van dit project is de 8x8 LED Matrix uit dit 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.
ArduinoBreadboard
Zie beschrijving in het project 8x8 LED Matrix
ArduinoSource code
/* 8x8 matrix / Circles (C) copyright www.punthooft.nl 2019-2023 */ #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 // Constants 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 }; // Variables int delayCounter; int direction; int row; int col; // Setup function runs once when powerup the board and on reset void setup() { // Open serial port Serial.begin(9600); delayCounter=0; direction = 1; row=0; col=0; } // The loop function runs over and over again forever 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); } // Function to display LED at position X,Y 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 2023 www.punthooft.nl
We do not collect cookies for advertisement. Your data is never send to third parties.