Introdução:
Esse display 8x8 é bem legal e fácil de usar, neste exemplo estamos ligando da forma mais simples, que é usando cada pino do arduino como entrada/saída. É possível usar registradores de deslocamento para economizar 90% dos pinos ,deixando livres para outras aplicações.
No blog existe um post com um display desses RGB que usa deslocadores, vale a pena conferir para ter uma ideia!
Características:
- Cor: Preto
- Material: Plástico
- Tensão: 1,8 ~ 2.6V, AMP: 5 ~ 15mA
- O pacote inclui:1 x Módulo
Ligando o Modulo:
Diagrama:
Código:
Para rodar esse código é necessário a biblioteca FrequencyTimer2, que pode ser baixada aqui.
/*
* Show messages on an 8x8 led matrix,
* scrolling from right to left.
*
* Uses FrequencyTimer2 library to
* constantly run an interrupt routine
* at a specified frequency. This
* refreshes the display without the
* main loop having to do anything.
*
*/
#include <FrequencyTimer2.h>
#define SPACE { \
{0, 0, 0, 0, 0, 0, 0, 0}, \
{0, 0, 0, 0, 0, 0, 0, 0}, \
{0, 0, 0, 0, 0, 0, 0, 0}, \
{0, 0, 0, 0, 0, 0, 0, 0}, \
{0, 0, 0, 0, 0, 0, 0, 0}, \
{0, 0, 0, 0, 0, 0, 0, 0}, \
{0, 0, 0, 0, 0, 0, 0, 0}, \
{0, 0, 0, 0, 0, 0, 0, 0} \
}
#define H { \
{0, 1, 0, 0, 0, 0, 1, 0}, \
{0, 1, 0, 0, 0, 0, 1, 0}, \
{0, 1, 0, 0, 0, 0, 1, 0}, \
{0, 1, 1, 1, 1, 1, 1, 0}, \
{0, 1, 0, 0, 0, 0, 1, 0}, \
{0, 1, 0, 0, 0, 0, 1, 0}, \
{0, 1, 0, 0, 0, 0, 1, 0}, \
{0, 1, 0, 0, 0, 0, 1, 0} \
}
#define E { \
{0, 1, 1, 1, 1, 1, 1, 0}, \
{0, 1, 0, 0, 0, 0, 0, 0}, \
{0, 1, 0, 0, 0, 0, 0, 0}, \
{0, 1, 1, 1, 1, 1, 1, 0}, \
{0, 1, 0, 0, 0, 0, 0, 0}, \
{0, 1, 0, 0, 0, 0, 0, 0}, \
{0, 1, 0, 0, 0, 0, 0, 0}, \
{0, 1, 1, 1, 1, 1, 1, 0} \
}
#define L { \
{0, 1, 0, 0, 0, 0, 0, 0}, \
{0, 1, 0, 0, 0, 0, 0, 0}, \
{0, 1, 0, 0, 0, 0, 0, 0}, \
{0, 1, 0, 0, 0, 0, 0, 0}, \
{0, 1, 0, 0, 0, 0, 0, 0}, \
{0, 1, 0, 0, 0, 0, 0, 0}, \
{0, 1, 0, 0, 0, 0, 0, 0}, \
{0, 1, 1, 1, 1, 1, 1, 0} \
}
#define O { \
{0, 0, 0, 1, 1, 0, 0, 0}, \
{0, 0, 1, 0, 0, 1, 0, 0}, \
{0, 1, 0, 0, 0, 0, 1, 0}, \
{0, 1, 0, 0, 0, 0, 1, 0}, \
{0, 1, 0, 0, 0, 0, 1, 0}, \
{0, 1, 0, 0, 0, 0, 1, 0}, \
{0, 0, 1, 0, 0, 1, 0, 0}, \
{0, 0, 0, 1, 1, 0, 0, 0} \
}
byte col = 0;
byte leds[8][8];
// pin[xx] on led matrix connected to nn on Arduino (-1 is dummy to make array start at pos 1)
int pins[17]= {-1, 5, 4, 3, 2, 14, 15, 16, 17, 13, 12, 11, 10, 9,8, 7, 6};
// col[xx] of leds = pin yy on led matrix
int cols[8] = {pins[13], pins[3], pins[4], pins[10], pins[06],pins[11], pins[15], pins[16]};
// row[xx] of leds = pin yy on led matrix
int rows[8] = {pins[9], pins[14], pins[8], pins[12], pins[1],pins[7], pins[2], pins[5]};
const int numPatterns = 6;
byte patterns[numPatterns][8][8] = {
H,E,L,L,O,SPACE
};
int pattern = 0;
void setup() {
// sets the pins as output
for (int i = 1; i <= 16; i++) {
pinMode(pins[i], OUTPUT);
}
// set up cols and rows
for (int i = 1; i <= 8; i++) {
digitalWrite(cols[i - 1], LOW);
}
for (int i = 1; i <= 8; i++) {
digitalWrite(rows[i - 1], LOW);
}
clearLeds();
// Turn off toggling of pin 11
FrequencyTimer2::disable();
// Set refresh rate (interrupt timeout period)
FrequencyTimer2::setPeriod(2000);
// Set interrupt routine to be called
FrequencyTimer2::setOnOverflow(display);
setPattern(pattern);
}
void loop() {
pattern = ++pattern % numPatterns;
slidePattern(pattern, 60);
}
void clearLeds() {
// Clear display array
for (int i = 0; i < 8; i++) {
for (int j = 0; j < 8; j++) {
leds[i][j] = 0;
}
}
}
void setPattern(int pattern) {
for (int i = 0; i < 8; i++) {
for (int j = 0; j < 8; j++) {
leds[i][j] = patterns[pattern][i][j];
}
}
}
void slidePattern(int pattern, int del) {
for (int l = 0; l < 8; l++) {
for (int i = 0; i < 7; i++) {
for (int j = 0; j < 8; j++) {
leds[j][i] = leds[j][i+1];
}
}
for (int j = 0; j < 8; j++) {
leds[j][7] = patterns[pattern][j][0 + l];
}
delay(del);
}
}
// Interrupt routine
void display() {
digitalWrite(cols[col], LOW); // Turn whole previous column off
col++;
if (col == 8) {
col = 0;
}
for (int row = 0; row < 8; row++) {
if (leds[col][7 - row] == 1) {
digitalWrite(rows[row], LOW); // Turn on this led
}
else {
digitalWrite(rows[row], HIGH); // Turn off this led
}
}
digitalWrite(cols[col], HIGH); // Turn whole column on at once (for equal lighting times)
* Show messages on an 8x8 led matrix,
* scrolling from right to left.
*
* Uses FrequencyTimer2 library to
* constantly run an interrupt routine
* at a specified frequency. This
* refreshes the display without the
* main loop having to do anything.
*
*/
#include <FrequencyTimer2.h>
#define SPACE { \
{0, 0, 0, 0, 0, 0, 0, 0}, \
{0, 0, 0, 0, 0, 0, 0, 0}, \
{0, 0, 0, 0, 0, 0, 0, 0}, \
{0, 0, 0, 0, 0, 0, 0, 0}, \
{0, 0, 0, 0, 0, 0, 0, 0}, \
{0, 0, 0, 0, 0, 0, 0, 0}, \
{0, 0, 0, 0, 0, 0, 0, 0}, \
{0, 0, 0, 0, 0, 0, 0, 0} \
}
#define H { \
{0, 1, 0, 0, 0, 0, 1, 0}, \
{0, 1, 0, 0, 0, 0, 1, 0}, \
{0, 1, 0, 0, 0, 0, 1, 0}, \
{0, 1, 1, 1, 1, 1, 1, 0}, \
{0, 1, 0, 0, 0, 0, 1, 0}, \
{0, 1, 0, 0, 0, 0, 1, 0}, \
{0, 1, 0, 0, 0, 0, 1, 0}, \
{0, 1, 0, 0, 0, 0, 1, 0} \
}
#define E { \
{0, 1, 1, 1, 1, 1, 1, 0}, \
{0, 1, 0, 0, 0, 0, 0, 0}, \
{0, 1, 0, 0, 0, 0, 0, 0}, \
{0, 1, 1, 1, 1, 1, 1, 0}, \
{0, 1, 0, 0, 0, 0, 0, 0}, \
{0, 1, 0, 0, 0, 0, 0, 0}, \
{0, 1, 0, 0, 0, 0, 0, 0}, \
{0, 1, 1, 1, 1, 1, 1, 0} \
}
#define L { \
{0, 1, 0, 0, 0, 0, 0, 0}, \
{0, 1, 0, 0, 0, 0, 0, 0}, \
{0, 1, 0, 0, 0, 0, 0, 0}, \
{0, 1, 0, 0, 0, 0, 0, 0}, \
{0, 1, 0, 0, 0, 0, 0, 0}, \
{0, 1, 0, 0, 0, 0, 0, 0}, \
{0, 1, 0, 0, 0, 0, 0, 0}, \
{0, 1, 1, 1, 1, 1, 1, 0} \
}
#define O { \
{0, 0, 0, 1, 1, 0, 0, 0}, \
{0, 0, 1, 0, 0, 1, 0, 0}, \
{0, 1, 0, 0, 0, 0, 1, 0}, \
{0, 1, 0, 0, 0, 0, 1, 0}, \
{0, 1, 0, 0, 0, 0, 1, 0}, \
{0, 1, 0, 0, 0, 0, 1, 0}, \
{0, 0, 1, 0, 0, 1, 0, 0}, \
{0, 0, 0, 1, 1, 0, 0, 0} \
}
byte col = 0;
byte leds[8][8];
// pin[xx] on led matrix connected to nn on Arduino (-1 is dummy to make array start at pos 1)
int pins[17]= {-1, 5, 4, 3, 2, 14, 15, 16, 17, 13, 12, 11, 10, 9,8, 7, 6};
// col[xx] of leds = pin yy on led matrix
int cols[8] = {pins[13], pins[3], pins[4], pins[10], pins[06],pins[11], pins[15], pins[16]};
// row[xx] of leds = pin yy on led matrix
int rows[8] = {pins[9], pins[14], pins[8], pins[12], pins[1],pins[7], pins[2], pins[5]};
const int numPatterns = 6;
byte patterns[numPatterns][8][8] = {
H,E,L,L,O,SPACE
};
int pattern = 0;
void setup() {
// sets the pins as output
for (int i = 1; i <= 16; i++) {
pinMode(pins[i], OUTPUT);
}
// set up cols and rows
for (int i = 1; i <= 8; i++) {
digitalWrite(cols[i - 1], LOW);
}
for (int i = 1; i <= 8; i++) {
digitalWrite(rows[i - 1], LOW);
}
clearLeds();
// Turn off toggling of pin 11
FrequencyTimer2::disable();
// Set refresh rate (interrupt timeout period)
FrequencyTimer2::setPeriod(2000);
// Set interrupt routine to be called
FrequencyTimer2::setOnOverflow(display);
setPattern(pattern);
}
void loop() {
pattern = ++pattern % numPatterns;
slidePattern(pattern, 60);
}
void clearLeds() {
// Clear display array
for (int i = 0; i < 8; i++) {
for (int j = 0; j < 8; j++) {
leds[i][j] = 0;
}
}
}
void setPattern(int pattern) {
for (int i = 0; i < 8; i++) {
for (int j = 0; j < 8; j++) {
leds[i][j] = patterns[pattern][i][j];
}
}
}
void slidePattern(int pattern, int del) {
for (int l = 0; l < 8; l++) {
for (int i = 0; i < 7; i++) {
for (int j = 0; j < 8; j++) {
leds[j][i] = leds[j][i+1];
}
}
for (int j = 0; j < 8; j++) {
leds[j][7] = patterns[pattern][j][0 + l];
}
delay(del);
}
}
// Interrupt routine
void display() {
digitalWrite(cols[col], LOW); // Turn whole previous column off
col++;
if (col == 8) {
col = 0;
}
for (int row = 0; row < 8; row++) {
if (leds[col][7 - row] == 1) {
digitalWrite(rows[row], LOW); // Turn on this led
}
else {
digitalWrite(rows[row], HIGH); // Turn off this led
}
}
digitalWrite(cols[col], HIGH); // Turn whole column on at once (for equal lighting times)
}
Parabéns pelo farto conhecimento. Inspirador!
ResponderExcluirVocê sabe o que devo usar no código para ligar o
shield GSM através da porta digital 6 do Arduino?
Obrigado.
Rogério
Olá Rogério,
ExcluirMuito obrigado, fico feliz !
Então sobre o Arduino e GSM, existem bibliotecas para usar o shield GSM, mas ne realidade os códigos são bem simples de interface serial para comunicar Arduino <-> GSM, usando comandos AT.
Já deu uma olhada nesse post:
http://microembarcado.blogspot.com.br/2012/09/review-arduino-gprs-shield-efcom-sim900.html
talvez possa te ajudar.
é isso ai
abs!
FrequencyTimer2::disable(); erro no programa 8x8 Dot Matrix
ResponderExcluir