Small 1.2" 8x8 LED Matrix w/I2C HELP SCROLLING

General project help for Adafruit customers

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
User avatar
Mysticforce
 
Posts: 20
Joined: Thu May 28, 2015 12:47 pm

Re: Small 1.2" 8x8 LED Matrix w/I2C HELP SCROLLING

Post by Mysticforce »

Please forgive me, but yes sir. Here is what I have tried so far. I have tried the println and others with this, but I just can't get it? What I am trying so hard to do is just scroll text across 1 to 4 of the i2c matrices with some effects. Like have the text drop in, scroll in from left to right, right to left, fill in and more and I have looked for code to mod and adjust but, no luck. That code below I know from what I have read has something to do with it, but I can't manage to get it. I can show you the other code I did that kinda of worked, but not what I would like it to do. I read programming Arduino and programming Arduino next steps and still can't figure out how to do my own code. I have been doing computers my whole life, but not coding in anyway. Any help would be greatly appreciated! Very greatly appreciated.

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);
  }
-Dave
Last edited by Mysticforce on Sat Jun 27, 2015 4:28 pm, edited 1 time in total.

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: Small 1.2" 8x8 LED Matrix w/I2C HELP SCROLLING

Post by adafruit_support_rick »

That will initialize the matrices.
Please post your entire sketch, including the snippet I gave you. I will attempt to modify it for you.

User avatar
Mysticforce
 
Posts: 20
Joined: Thu May 28, 2015 12:47 pm

Re: Small 1.2" 8x8 LED Matrix w/I2C HELP SCROLLING

Post by Mysticforce »

This is how I hacked this code and it kind of works. It only works with one matrix. That is why I wanted to use that code above to be able to choose 1 to 4 matrices and I only want to scroll text with effects not the bmp's. This was the only way I could get the text that I wanted to scroll, but even that don't really work well.



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);
}

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: Small 1.2" 8x8 LED Matrix w/I2C HELP SCROLLING

Post by adafruit_support_rick »

Let's start with this. I don't happen to have two of these matrices to test with, so I haven't actually run this code. But see what happens with it:

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);
  }
}

User avatar
Mysticforce
 
Posts: 20
Joined: Thu May 28, 2015 12:47 pm

Re: Small 1.2" 8x8 LED Matrix w/I2C HELP SCROLLING

Post by Mysticforce »

Hello Rick,
Thank you so much. Code works, but I have a question for you. I know from the code you shared I can add a third and fourth matrices by adding matrix3 and matrix4 through out the code. The only issue is that there is a pause between words. So it doesn't quite scroll smoothly. So I tried to have it scroll the entire sentence in one Scroll line, but when I try this code below to keep the words scrolling without a pause it cuts off after the word "Galloway". Why does it cut off? The code change I am asking about is the first scrolling line.

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);
  }
}


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? I would like to learn several ways to scroll the texts. I know I am really pushing it now, but I would like to add some effects. Like scrolling in from different directions and maybe like a fade in or something. Thank you so very much for you help, time and patients. I appreciate it so much. Plus I know there are others who will be very excited about this code and what we work out here. I am going to post it on my you tube channel if that is ok with you.

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();
  }
Sincerely,
-Dave

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: Small 1.2" 8x8 LED Matrix w/I2C HELP SCROLLING

Post by adafruit_support_rick »

For longer strings, you'll have to increase the 72 to something larger. Make it the (string length * 8 ) plus 32:

Code: Select all

void Scroll(char* text)
{
  int scrollPositions = (strlen(text) * 8) + 32;
  for (int x=0; x>=-scrollPositions; x--) {
   . . . etc . . .
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?
It can work. This compiles - I don't know how well it works - I haven't tried it:

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);
  }
}

User avatar
Mysticforce
 
Posts: 20
Joined: Thu May 28, 2015 12:47 pm

Re: Small 1.2" 8x8 LED Matrix w/I2C HELP SCROLLING

Post by Mysticforce »

Rick,
Dude! I love ya Man! (In a manly sorta way) Thank you so very much. Both codes work great. Just one more question if that is ok. Actually two more questions please. One the delay from when that scrolling text ends and when it starts over is almost 10 seconds is there a way to reduce that? Now the next question; do you mind if I post this to my you tube channel? Of course your getting full props for this because I didn't really do anything, but hack some other code to get this started. I am trying to learn how to arduino code and I will learn it, some how some way. I will not give up. Thanks for all your help Rick. One more question and this is kinda like a bonus thing and you don't have to help in anyway on this because I am so stoked about this working now. Is there anyway we could add some effects to the text? I know I can switch directions of the scrolling text, but is there a way to do like a fade in or drop in from the top, or any other cool effect? Thanks Again Rick!

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: Small 1.2" 8x8 LED Matrix w/I2C HELP SCROLLING

Post by adafruit_support_rick »

Cool! I love it when untested code just works.

Regarding the delay between the end of the string and the start of the next - I was just guessing at this part:

Code: Select all

  int scrollPositions = (strlen(text) * 8) + 32;
That obviously comes up with too large a number. You can try playing with it - try times 4 instead of times 8. twiddle the numbers until you get what you want.

You can certainly post this to YouTube!

Adding additional effects to the scrolling can get complicated fast. It really depends on what you want to do.

User avatar
Mysticforce
 
Posts: 20
Joined: Thu May 28, 2015 12:47 pm

Re: Small 1.2" 8x8 LED Matrix w/I2C HELP SCROLLING

Post by Mysticforce »

Rick,
Thank you. I got it perfect thanks to you. Appreciate everything so much. I know there are others who will appreciate it too. Thanks again. Since you have already helped me beyond measure I was wondering if you could lead me to a place or code that I can figure out how to add some effects.

-Dave

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: Small 1.2" 8x8 LED Matrix w/I2C HELP SCROLLING

Post by adafruit_support_rick »

What effects are you interested in? Pick one, describe it, and I'll see if I can help.

Locked
Please be positive and constructive with your questions and comments.

Return to “General Project help”