LED Matrix
led_matrix.ino
/*
Project: Smart Home
Component: Arduino Ek R4 Built-in LED Matrix
Project Description: This sketch has function to display text and graphics on the built-in LED Matrix.
Author: STEMVentor Educonsulting
This code is copyrighted. Please do not reuse or share for any purpose other than for learning with subscribed STEMVentor programs.
This code is for educational purposes only and is not for production use.
*/
// LIBRARIES
// Include the ArduinoGraphics library before the Arduino_LED_Matrix library
#include "ArduinoGraphics.h"
#include "Arduino_LED_Matrix.h"
// PIN DEFINITIONS
// Defined in env.h
// GLOBAL CONSTANTS
// LED Matrix Frames
// This is what is generated by the Arduino frame creator tool.
// Does not work, take the three HEX values and create a variable
// in the structure expected by the LED matrix library.
// const uint32_t LEDMATRIX_FRAME_WIFI[][4] = {
// {
// 0x8bd8a,
// 0x8bdaa1a,
// 0xa1fa1000,
// 66
// }
// };
// INITIALIZE OBJECTS
/* Libraries usually follow an object-oriented approach that requires
* an instance of the class to call its methods.
*/
// The Arduino Ek R4 LED Matrix only displays the color red.
ArduinoLEDMatrix matrix;
// LOCAL FUNCTIONS
void LEDMatrixSetup() {
matrix.begin();
// Load and display the an emoji frame from the gallery.
matrix.loadFrame(LEDMATRIX_EMOJI_BASIC);
delay(2000);
// Load and display an animation from the gallery.
matrix.loadSequence(LEDMATRIX_ANIMATION_STARTUP);
matrix.play(true);
delay(2000);
scrollPrintToLEDMatrix("Ready!");
}
// Functions to be called by other sketches to display some text.
// We will largely use it only to display connection status
// WiFi, BLE, or NC (not connected).
void displayWiFiOnLEDMatrix(){
const unsigned long LEDMATRIX_FRAME_WIFI[3] = {
0x8bd8a,
0x8bdaa1a,
0xa1fa1000
};
matrix.loadFrame(LEDMATRIX_FRAME_WIFI);
}
void displayBLEOnLEDMatrix(){
const unsigned long LEDMATRIX_FRAME_BLE[3] = {
0x84784,
0x4847f449,
0x44f77000
};
matrix.loadFrame(LEDMATRIX_FRAME_BLE);
}
void displayNotConnectedOnLEDMatrix(){
const unsigned long LEDMATRIX_FRAME_NOT_CONNECTED[3] = {
0x10809,
0x600600,
0x90108000
};
matrix.loadFrame(LEDMATRIX_FRAME_NOT_CONNECTED);
}
void staticPrintToLEDMatrix(char text[]) {
matrix.beginDraw();
matrix.textFont(Font_4x6);
matrix.beginText(0, 1, 0xFFFFFF);
matrix.println(text);
matrix.endText();
matrix.endDraw();
}
void scrollPrintToLEDMatrix(char text[]) {
// Make it scroll!
matrix.beginDraw();
matrix.textScrollSpeed(50);
// const char text[] = " Ready! ";
matrix.textFont(Font_4x6);
matrix.beginText(0, 1, 0xFFFFFF);
matrix.println(text);
matrix.endText(SCROLL_LEFT);
matrix.endDraw();
}