In this video lesson we create a bouncing pixel on the Arduino Uno R4 LED Matrix. For your convenience we include the code developed in the video below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | #include "Arduino_LED_Matrix.h" ArduinoLEDMatrix matrix; int br=115200; int dt=50; int xPos=3; int yPos=2; int deltaX=1; int deltaY=1; int i; int j; byte frame[8][12]; void setup() { // put your setup code here, to run once: Serial.begin(br); matrix.begin(); } void loop() { // put your main code here, to run repeatedly: for ( i=0;i<=11;i=i+1){ for (j=0;j<=7;j=j+1){ frame[j][i]=0; if (i==xPos && j==yPos){ frame[j][i]=1; } } } matrix.renderBitmap(frame,8,12); if (xPos>=11 || xPos<=0){ deltaX=-deltaX; } if (yPos>=7 || yPos<=0){ deltaY=-deltaY; } xPos=xPos+deltaX; yPos=yPos+deltaY; delay(dt); } |