This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| en:iot:examples:matrix [2019/11/19 20:27] – heikopikner | en:iot:examples:matrix [Unknown date] (current) – external edit (Unknown date) 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | ====== LED Matrix example ====== | ||
| + | {{: | ||
| + | |||
| + | Needed libraries: | ||
| + | < | ||
| + | |||
| + | For learning how to use the IoT Matrix you can try out the example and tasks. | ||
| + | |||
| + | <code c> | ||
| + | /* 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(" | ||
| + | } | ||
| + | |||
| + | void loop() { | ||
| + | matrix.clear(); | ||
| + | matrix.drawRect(0, | ||
| + | matrix.fillRect(2, | ||
| + | matrix.writeDisplay(); | ||
| + | delay(500); // Wait for half a second | ||
| + | matrix.drawRect(0, | ||
| + | matrix.drawRect(1, | ||
| + | matrix.fillRect(2, | ||
| + | matrix.writeDisplay(); | ||
| + | delay(500); | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | {{: | ||
| + | |||
| + | Trips-traps-trull | ||
| + | |||
| + | <code c> | ||
| + | #include < | ||
| + | #include < | ||
| + | #include < | ||
| + | #include < | ||
| + | #include < | ||
| + | |||
| + | MLED matrix(7); | ||
| + | |||
| + | void setup() { | ||
| + | Serial.begin(9600); | ||
| + | Serial.println(" | ||
| + | } | ||
| + | |||
| + | void loop() { | ||
| + | matrix.clear(); | ||
| + | for (int i = 0; i <= 7; i++) { | ||
| + | matrix.drawRect(i, | ||
| + | matrix.writeDisplay(); | ||
| + | delay(100); | ||
| + | } | ||
| + | for (int i = 0; i < 8; i++) { | ||
| + | matrix.drawRect(i, | ||
| + | matrix.writeDisplay(); | ||
| + | delay(100); | ||
| + | } | ||
| + | for (int i = 0; i < 8; i++) { | ||
| + | matrix.drawRect(1, | ||
| + | matrix.writeDisplay(); | ||
| + | delay(50); | ||
| + | } | ||
| + | for (int i = 0; i < 8; i++) { | ||
| + | matrix.drawRect(5, | ||
| + | matrix.writeDisplay(); | ||
| + | delay(50); | ||
| + | } | ||
| + | delay(1000); | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | {{: | ||
| + | |||
| + | Ringiratast ekraani täitmine | ||
| + | |||
| + | <code c> | ||
| + | #include < | ||
| + | #include < | ||
| + | #include < | ||
| + | #include < | ||
| + | #include < | ||
| + | |||
| + | MLED matrix(7); | ||
| + | |||
| + | void setup() { | ||
| + | Serial.begin(9600); | ||
| + | Serial.println(" | ||
| + | } | ||
| + | |||
| + | void drawRight(int a, int b, int c) { | ||
| + | for (int i = c; i <= a+c; i++) { | ||
| + | matrix.drawRect(i, | ||
| + | matrix.writeDisplay(); | ||
| + | delay(100); | ||
| + | } | ||
| + | } | ||
| + | |||
| + | void drawDown(int a, int b) { | ||
| + | for (int i = b; i <= a; i++) { | ||
| + | matrix.drawRect(a, | ||
| + | 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, | ||
| + | matrix.writeDisplay(); | ||
| + | delay(100); | ||
| + | } | ||
| + | } | ||
| + | |||
| + | void drawUp(int a, int b, int c) { | ||
| + | for (int i = 0; i <= a; i++) { | ||
| + | matrix.drawRect(c, | ||
| + | matrix.writeDisplay(); | ||
| + | delay(100); | ||
| + | } | ||
| + | } | ||
| + | |||
| + | void loop() { | ||
| + | matrix.clear(); | ||
| + | drawRight(7, | ||
| + | drawDown(7, | ||
| + | drawLeft(6, | ||
| + | drawUp(4, | ||
| + | drawRight(6, | ||
| + | drawDown(6, | ||
| + | drawLeft(4, | ||
| + | drawUp(2, | ||
| + | drawRight(3, | ||
| + | drawDown(5, | ||
| + | drawLeft(2, | ||
| + | drawUp(1, | ||
| + | drawRight(0, | ||
| + | drawDown(4, | ||
| + | drawLeft(0, | ||
| + | delay(400); | ||
| + | } | ||
| + | |||
| + | </ | ||
| + | |||
| + | {{: | ||