====== LED Matrix example ======
{{:en:iot:examples:matrixmodule.png?200|}}
Needed libraries:
lib_deps = WEMOS Matrix Adafruit GFX@1.3, Adafruit GFX Library@1.7.2, adafruit/Adafruit BusIO@^1.6.0
For learning how to use the IoT Matrix you can try out the example and tasks.
/* Switching boxes */
// Librarys that the IoT Matrix uses
#include
#include
#include
#include
#include
MLED matrix(7); //set intensity=7 (maximum)
void setup() {
Serial.begin(9600);
Serial.println("8x8 LED Matrix Test");
}
void loop() {
matrix.clear(); // Clear the matrix field
matrix.drawRect(0,0, 8,8, LED_ON); // Draws a empty square with positions y = 0, x = 0, y length = 8, x length = 8 and telling the leds to be on.
matrix.fillRect(2,2, 4,4, LED_ON); // Draws a filled square from positions y = 2, x = 2, y length = 4, x length = 4 and telling the leds to turn on
matrix.writeDisplay(); // Write the changes we just made to the display
delay(500); // Wait for half a second
matrix.drawRect(0,0,8,8, LED_OFF); // Turn the leds off
matrix.drawRect(1,1, 6,6, LED_ON);
matrix.fillRect(2,2,4,4, LED_OFF);
matrix.writeDisplay();
delay(500);
}
{{:en:iot:examples:kastid1.png?200|}} {{:en:iot:examples:kastid2.png?200|}}
Trips-traps-trull
#include
#include
#include
#include
#include
MLED matrix(7);
void setup() {
Serial.begin(9600);
Serial.println("8x8 LED Matrix Test");
}
void loop() {
matrix.clear();
for (int i = 0; i <= 7; i++) {
matrix.drawRect(i,1, 1,2, LED_ON);
matrix.writeDisplay();
delay(100);
}
for (int i = 0; i < 8; i++) {
matrix.drawRect(i,5, 1,2, LED_ON);
matrix.writeDisplay();
delay(100);
}
for (int i = 0; i < 8; i++) {
matrix.drawRect(1,i, 2,1, LED_ON);
matrix.writeDisplay();
delay(50);
}
for (int i = 0; i < 8; i++) {
matrix.drawRect(5,i, 2,1, LED_ON);
matrix.writeDisplay();
delay(50);
}
delay(1000);
}
{{:en:iot:examples:tripstraps.png?200|}}
Ringiratast ekraani täitmine
#include
#include
#include
#include
#include
MLED matrix(7);
void setup() {
Serial.begin(9600);
Serial.println("8x8 LED Matrix Test");
}
void drawRight(int a, int b, int c) {
for (int i = c; i <= a+c; i++) {
matrix.drawRect(i,b,1,1, LED_ON);
matrix.writeDisplay();
delay(100);
}
}
void drawDown(int a, int b) {
for (int i = b; i <= a; i++) {
matrix.drawRect(a,i,1,1, LED_ON);
matrix.writeDisplay();
delay(100);
}
}
void drawLeft(int a, int b) {
int e = 0;
for (int i = 0; i <= a; i++) {
e++;
matrix.drawRect(b-e,b,1,1, LED_ON);
matrix.writeDisplay();
delay(100);
}
}
void drawUp(int a, int b, int c) {
for (int i = 0; i <= a; i++) {
matrix.drawRect(c,b-i,1,1, LED_ON);
matrix.writeDisplay();
delay(100);
}
}
void loop() {
matrix.clear();
drawRight(7,0,0);
drawDown(7,1);
drawLeft(6,7);
drawUp(4,6,0);
drawRight(6,1,0);
drawDown(6,2);
drawLeft(4,6);
drawUp(2,5,1);
drawRight(3,2,1);
drawDown(5,2);
drawLeft(2,5);
drawUp(1,4,2);
drawRight(0,3,3);
drawDown(4,3);
drawLeft(0,4);
delay(400);
}
{{:en:iot:examples:lab1.png?100|}} {{:en:iot:examples:lab2.png?100|}} {{:en:iot:examples:lab3.png?100|}} {{:en:iot:examples:lab4.png?100|}} {{:en:iot:examples:lab5.png?100|}}