LED Matrix example

Needed libraries:

lib_deps = ITTIoT, WEMOS_Matrix_GFX, Adafruit GFX Library

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 <Arduino.h>
#include <ittiot.h>
#include <Adafruit_GFX.h>
#include <WEMOS_Matrix_GFX.h>
#include <SPI.h>
 
MLED matrix(7); //set intensity=7 (maximum)
 
void setup() {
  Serial.begin(9600);
  Serial.println("8x8 LED Matrix Test");
 
  iot.printConfig(); // Print json config to serial monitor at distancelab website
  iot.setup();
 
 
}
 
void loop() {
 
  iot.handle();
 
  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);
}

Tic-Tac-Toe

#include <Arduino.h>
#include <ittiot.h>
#include <Adafruit_GFX.h>
#include <WEMOS_Matrix_GFX.h>
#include <SPI.h>
 
MLED matrix(7);
 
void setup() {
  Serial.begin(9600);
  Serial.println("8x8 LED Matrix Test");
 
  iot.printConfig();
  iot.setup();
}
 
void loop() {
  iot.handle();
  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);
}

Make everything covered one by one in a circular way

#include <Arduino.h>
#include <ittiot.h>
#include <Adafruit_GFX.h>
#include <WEMOS_Matrix_GFX.h>
#include <SPI.h>
 
MLED matrix(7);
 
void setup() {
  Serial.begin(9600);
  Serial.println("8x8 LED Matrix Test");
 
  iot.printConfig();
  iot.setup();
}
 
int 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);
  }
}
 
int drawDown(int a, int b) {
  for (int i = b; i <= a; i++) {
    matrix.drawRect(a,i,1,1, LED_ON);
    matrix.writeDisplay();
    delay(100);
  }
}
 
int 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);
  }
}
 
int 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() {
  iot.handle();
  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/matrix.txt · Last modified: 2018/05/21 11:33 by Somepub
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0