Code: Select all
#include <Wire.h>
#include "Adafruit_LEDBackpack.h"
#include "Adafruit_GFX.h"
Adafruit_8x8matrix matrix[4];
for(uint8_t i=0; i<4; i++) {
matrix[i] = Adafruit_8x8matrix();
matrix[i].begin(0x70 + i);
}
Moderators: adafruit_support_bill, adafruit
Code: Select all
#include <Wire.h>
#include "Adafruit_LEDBackpack.h"
#include "Adafruit_GFX.h"
Adafruit_8x8matrix matrix[4];
for(uint8_t i=0; i<4; i++) {
matrix[i] = Adafruit_8x8matrix();
matrix[i].begin(0x70 + i);
}
Code: Select all
/***************************************************
This is a library for our I2C LED Backpacks
Designed specifically to work with the Adafruit LED Matrix backpacks
----> http://www.adafruit.com/products/872
----> http://www.adafruit.com/products/871
----> http://www.adafruit.com/products/870
These displays use I2C to communicate, 2 pins are required to
interface. There are multiple selectable I2C addresses. For backpacks
with 2 Address Select pins: 0x70, 0x71, 0x72 or 0x73. For backpacks
with 3 Address Select pins: 0x70 thru 0x77
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
Written by Limor Fried/Ladyada for Adafruit Industries.
BSD license, all text above must be included in any redistribution
****************************************************/
#include <Wire.h>
#include "Adafruit_LEDBackpack.h"
#include "Adafruit_GFX.h"
Adafruit_8x8matrix matrix = Adafruit_8x8matrix();
void setup() {
Serial.begin(9600);
Serial.println("8x8 LED Matrix Test");
matrix.begin(0x70); // pass in the address
}
static const uint8_t PROGMEM
smile_bmp[] =
{ B00111100,
B01000010,
B10100101,
B10000001,
B10100101,
B10011001,
B01000010,
B00111100 },
neutral_bmp[] =
{ B00111100,
B01000010,
B10100101,
B10000001,
B10111101,
B10000001,
B01000010,
B00111100 },
frown_bmp[] =
{ B00111100,
B01000010,
B10100101,
B10000001,
B10011001,
B10100101,
B01000010,
B00111100 };
void loop() {
matrix.clear();
matrix.drawBitmap(0, 0, smile_bmp, 8, 8, LED_ON);
matrix.writeDisplay();
delay(500);
matrix.clear();
matrix.drawBitmap(0, 0, neutral_bmp, 8, 8, LED_ON);
matrix.writeDisplay();
delay(500);
matrix.clear();
matrix.drawBitmap(0, 0, frown_bmp, 8, 8, LED_ON);
matrix.writeDisplay();
delay(500);
matrix.clear(); // clear display
matrix.drawPixel(0, 0, LED_ON);
matrix.writeDisplay(); // write the changes we just made to the display
delay(500);
matrix.clear();
matrix.drawLine(0,0, 7,7, LED_ON);
matrix.writeDisplay(); // write the changes we just made to the display
delay(500);
matrix.clear();
matrix.drawRect(0,0, 8,8, LED_ON);
matrix.fillRect(2,2, 4,4, LED_ON);
matrix.writeDisplay(); // write the changes we just made to the display
delay(500);
matrix.clear();
matrix.drawCircle(3,3, 3, LED_ON);
matrix.writeDisplay(); // write the changes we just made to the display
delay(500);
matrix.setTextSize(1);
matrix.setTextWrap(false); // we dont want text to wrap so it scrolls nicely
matrix.setTextColor(LED_ON);
matrix.setRotation(3);
for (int8_t x=0; x>=-36; x--) {
matrix.clear();
matrix.setCursor(x,0);
matrix.print("David");
matrix.writeDisplay();
delay(100);
}
matrix.setRotation(3);
for (int8_t x=7; x>=-64; x--) {
matrix.clear();
matrix.setCursor(x,0);
matrix.print("Galloway");
matrix.writeDisplay();
delay(100);
}
matrix.setRotation(3);
for (int8_t x=7; x>=-36; x--) {
matrix.clear();
matrix.setCursor(x,0);
matrix.print("k3wiz");
matrix.writeDisplay();
delay(100);
}
matrix.setRotation(3);
for (int8_t x=7; x>=-36; x--) {
matrix.clear();
matrix.setCursor(x,0);
matrix.print("from");
matrix.writeDisplay();
delay(100);
}
matrix.setRotation(3);
for (int8_t x=7; x>=-64; x--) {
matrix.clear();
matrix.setCursor(x,0);
matrix.print("My Town,");
matrix.writeDisplay();
delay(100);
}
matrix.setRotation(3);
for (int8_t x=7; x>=-36; x--) {
matrix.clear();
matrix.setCursor(x,0);
matrix.print("PA");
matrix.writeDisplay();
delay(100);
}
matrix.setRotation(0);
}
Code: Select all
/***************************************************
This is a library for our I2C LED Backpacks
Designed specifically to work with the Adafruit LED Matrix backpacks
----> http://www.adafruit.com/products/872
----> http://www.adafruit.com/products/871
----> http://www.adafruit.com/products/870
These displays use I2C to communicate, 2 pins are required to
interface. There are multiple selectable I2C addresses. For backpacks
with 2 Address Select pins: 0x70, 0x71, 0x72 or 0x73. For backpacks
with 3 Address Select pins: 0x70 thru 0x77
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
Written by Limor Fried/Ladyada for Adafruit Industries.
BSD license, all text above must be included in any redistribution
****************************************************/
#include <Wire.h>
#include "Adafruit_LEDBackpack.h"
#include "Adafruit_GFX.h"
Adafruit_8x8matrix matrix1 = Adafruit_8x8matrix();
Adafruit_8x8matrix matrix2 = Adafruit_8x8matrix();
void setup() {
Serial.begin(9600);
Serial.println("8x8 LED Matrix Test");
matrix1.begin(0x70); // pass in the address
matrix2.begin(0x71);
}
void loop() {
matrix1.clear();
matrix2.clear();
matrix1.setTextSize(1);
matrix1.setTextWrap(false); // we dont want text to wrap so it scrolls nicely
matrix1.setTextColor(LED_ON);
matrix1.setRotation(3);
matrix2.setTextSize(1);
matrix2.setTextWrap(false); // we dont want text to wrap so it scrolls nicely
matrix2.setTextColor(LED_ON);
matrix2.setRotation(3);
Scroll("David");
Scroll("Galloway");
Scroll("k3wiz");
Scroll("from");
Scroll("My Town");
Scroll("Pa");
matrix1.setRotation(0);
matrix2.setRotation(0);
}
void Scroll(char* text)
{
for (int8_t x=0; x>=-72; x--) {
matrix1.clear();
matrix2.clear();
matrix1.setCursor(x,0);
matrix2.setCursor(x-8,0);
matrix1.print(text);
matrix2.print(text);
matrix1.writeDisplay();
matrix2.writeDisplay();
delay(100);
}
}
Code: Select all
/***************************************************
This is a library for our I2C LED Backpacks
Designed specifically to work with the Adafruit LED Matrix backpacks
----> http://www.adafruit.com/products/872
----> http://www.adafruit.com/products/871
----> http://www.adafruit.com/products/870
These displays use I2C to communicate, 2 pins are required to
interface. There are multiple selectable I2C addresses. For backpacks
with 2 Address Select pins: 0x70, 0x71, 0x72 or 0x73. For backpacks
with 3 Address Select pins: 0x70 thru 0x77
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
Written by Limor Fried/Ladyada for Adafruit Industries.
BSD license, all text above must be included in any redistribution
****************************************************/
#include <Wire.h>
#include "Adafruit_LEDBackpack.h"
#include "Adafruit_GFX.h"
Adafruit_8x8matrix matrix1 = Adafruit_8x8matrix();
Adafruit_8x8matrix matrix2 = Adafruit_8x8matrix();
void setup() {
Serial.begin(9600);
Serial.println("8x8 LED Matrix Test");
matrix1.begin(0x70); // pass in the address
matrix2.begin(0x71);
}
void loop() {
matrix1.clear();
matrix2.clear();
matrix1.setTextSize(1);
matrix1.setTextWrap(false); // we dont want text to wrap so it scrolls nicely
matrix1.setTextColor(LED_ON);
matrix1.setRotation(3);
matrix2.setTextSize(1);
matrix2.setTextWrap(false); // we dont want text to wrap so it scrolls nicely
matrix2.setTextColor(LED_ON);
matrix2.setRotation(3);
Scroll("David Galloway K3WIZ from My Town, Pa.");
/*
* Scroll("Galloway");
* Scroll("k3wiz");
* Scroll("from");
* Scroll("My Town");
* Scroll("Pa");
*/
matrix1.setRotation(0);
matrix2.setRotation(0);
}
void Scroll(char* text)
{
for (int8_t x=0; x>=-72; x--) {
matrix1.clear();
matrix2.clear();
matrix1.setCursor(x,0);
matrix2.setCursor(x-8,0);
matrix1.print(text);
matrix2.print(text);
matrix1.writeDisplay();
matrix2.writeDisplay();
delay(100);
}
}
Code: Select all
we’ll usually find it easier to declare an object array. There are four unique matrix addresses so we declare a four-element array:
Adafruit_8x8matrix matrix[4];
Each object can then be instantiated and initialized in the setup() function (using a loop if we like):
for(uint8_t i=0; i<4; i++) {
matrix[i] = Adafruit_8x8matrix();
matrix[i].begin(0x70 + i);
}
To issue commands to a specific matrix, we follow the array name (“matrix”) with an index — the element number in the array (a four-element array has indices 0 through 3). The syntax and parameters are otherwise the same as the single-matrix example. Here we issue different commands to each of four matrices in an array:
matrix[0].clear();
matrix[1].clear();
matrix[0].setTextSize(1);
matrix[0].setTextWrap(false); // we dont want text to wrap so it scrolls nicely
matrix[0].setTextColor(LED_ON);
matrix[0].setRotation(3);
matrix[1].setTextSize(1);
matrix[1].setTextWrap(false); // we dont want text to wrap so it scrolls nicely
matrix[1].setTextColor(LED_ON);
matrix[1].setRotation(3);
To refresh each display! We can use a loop if we like:
for(uint8_t i=0; i<4; i++) {
matrix[i].writeDisplay();
}
Code: Select all
void Scroll(char* text)
{
int scrollPositions = (strlen(text) * 8) + 32;
for (int x=0; x>=-scrollPositions; x--) {
. . . etc . . .
It can work. This compiles - I don't know how well it works - I haven't tried it:Mysticforce wrote:Aslo here is another question I have which is a little different from the one above. So I am wondering if the code below will work, it is only partial code as an example of what I am thinking of....and I was wondering what you think? Would that be easier to implement for adding or subtracting a matrice(s) and could you help with that?
Code: Select all
#include <Wire.h>
#include "Adafruit_LEDBackpack.h"
#include "Adafruit_GFX.h"
#define NUM_MATRICES 2
Adafruit_8x8matrix matrix[NUM_MATRICES];
void setup() {
Serial.begin(9600);
Serial.println("8x8 LED Matrix Test");
for(uint8_t m=0; m<NUM_MATRICES; m++) {
matrix[m].begin(0x70 + m);
}
}
void loop() {
for(uint8_t m=0; m<NUM_MATRICES; m++) {
matrix[m].clear();
matrix[m].setTextSize(1);
matrix[m].setTextWrap(false); // we dont want text to wrap so it scrolls nicely
matrix[m].setTextColor(LED_ON);
matrix[m].setRotation(3);
}
Scroll("David Galloway K3WIZ from My Town, Pa.");
/*
* Scroll("Galloway");
* Scroll("k3wiz");
* Scroll("from");
* Scroll("My Town");
* Scroll("Pa");
*/
}
void Scroll(char* text)
{
int scrollPositions = (strlen(text) * 8) + 32;
for (int x=0; x>=-scrollPositions; x--) {
for(uint8_t m=0; m<NUM_MATRICES; m++) {
matrix[m].clear();
matrix[m].setCursor((x - (m * 8)), 0);
matrix[m].print(text);
matrix[m].writeDisplay();
}
delay(100);
}
}
Code: Select all
int scrollPositions = (strlen(text) * 8) + 32;