Skip to content

Adding a function to print scrolling text to the display #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions Max72xxPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
All text above must be included in any redistribution.
******************************************************************/

#include "Arduino.h"
#include <Adafruit_GFX.h>
#include "Max72xxPanel.h"
#include <SPI.h>
Expand Down Expand Up @@ -192,3 +193,31 @@ void Max72xxPanel::spiTransfer(byte opcode, byte data) {
// Latch the data onto the display(s)
digitalWrite(SPI_CS, HIGH);
}

void Max72xxPanel::printToDisplay(String tape, int wait, int letter_width, int spacer) {
spacer += 1;
letter_width += 6;

letter_width += spacer; // Add the spacer width to the letter width to get the real width
int matrix_width = this->Adafruit_GFX::width();
int height = this->Adafruit_GFX::height();

for(int i = 0; i < letter_width * tape.length() + matrix_width - 1 - spacer; i++) {
this->fillScreen(LOW);

int letter = i / letter_width;
int x = (matrix_width - 1) - i % letter_width;
int y = (height - 8) / 2; // center the text vertically

while(x + letter_width - spacer >= 0 && letter >= 0) {
if(letter < tape.length()) {
this->Adafruit_GFX::drawChar(x, y, tape[letter], HIGH, LOW, 1);
}

letter--;
x -= letter_width;
}
this->write();
delay(wait);
}
}
12 changes: 9 additions & 3 deletions Max72xxPanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,15 @@ class Max72xxPanel : public Adafruit_GFX {
*/
void write();

/*
* Writes a tape to the display in scrolling text format
* Parameters:
* spacer is space between letters
* letter_width is letter width
* wait controls the speed of text flow
*/
void printToDisplay(String tape, int wait, int letter_width = 0, int spacer = 0);

private:
byte SPI_CS; /* SPI chip selection */

Expand All @@ -115,6 +124,3 @@ class Max72xxPanel : public Adafruit_GFX {
};

#endif // Max72xxPanel_h



18 changes: 12 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
Max72xxPanel
============
# TinkerTech Max72xxPanel Arduino Library

An Arduino library for controlling a canvas of sets of 8x8 LEDs driven by MAX7219 or MAX7221 controllers. [Kits][hardware] sold for below 10 USD.

This is a plugin for Adafruit's core graphics library GFX, providing basic graphics primitives (points, lines, circles, characters, etc.). So besides this library, you need to download and install [Adafruit_GFX][gfx-download], *dated Jul 5th, 2013 or more recent*.
This is a plugin for Adafruit's core graphics library GFX, providing basic graphics primitives (points, lines, circles, characters, etc.). So besides this library, you need to download and install [Adafruit_GFX][gfx-download], *dated Jul 5th, 2013 or more recent*.

Written by Mark Ruys, <mark@paracas.nl>, 2013.
Created by Mark Ruys, <mark@paracas.nl>, 2013.

Edited by Patrick Neggie <patmn@umich.edu> 2018.


Installation
------------

Place the [Max72xxPanel][download] and [Adafruit_GFX][gfx-download] library folders in your `<arduinosketchfolder>/libraries/` folder. You may need to create the `libraries` subfolder if its your first library. Restart the Arduino IDE.
Place the [Max72xxPanel][download] and [Adafruit_GFX][gfx-download] library folders in your `<arduinosketchfolder>/libraries/` folder. You may need to create the `libraries` subfolder if its your first library. Restart the Arduino IDE.


Features
Expand All @@ -21,6 +22,11 @@ Features
- Uses the [SPI library][spi] to address the display(s) connected in cascade.
- Low memory footprint.
- Fast, no use of NOOP's.
- Easy usage, one-line function to print text to display

Notable Additions
-----
A new function in the format `void printToDisplay(String tape, int wait)` takes in a two parameters: a string of what to print to the display and a integer wait time to change how fast the text scrolls on the display.

Usage
-----
Expand All @@ -37,4 +43,4 @@ At YouTube, you'll find a [ticker tape][tickertape] and [snake] demo.
[hardware]: https://www.google.com/search?q=MAX7219+Red+Dot+Matrix+Module "For kits, google MAX7219 Red Dot Matrix Module"
[spi]: http://arduino.cc/en/Reference/SPI "SPI library"
[tickertape]: http://www.youtube.com/watch?v=a8T7ZFeaf1A "Max72xxPanel Arduino library demo (ticker tape)"
[snake]: http://www.youtube.com/watch?v=FbJJyuCwohs "Max72xxPanel Arduino library demo (snake)"
[snake]: http://www.youtube.com/watch?v=FbJJyuCwohs "Max72xxPanel Arduino library demo (snake)"
37 changes: 37 additions & 0 deletions examples/ScrollingText/ScrollingText.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Max72xxPanel.h>

int pinCS = 10; // Attach CS to this pin, DIN to MOSI and CLK to SCK (cf http://arduino.cc/en/Reference/SPI )
// i.e. connect CS to 10, DIN to 11, CLK to 13 for Arduino Uno
int numberOfHorizontalDisplays = 8;
int numberOfVerticalDisplays = 1;

Max72xxPanel matrix = Max72xxPanel(pinCS, numberOfHorizontalDisplays, numberOfVerticalDisplays);

String tape = "Hello :)";
int wait = 20; // In milliseconds

void setup() {

matrix.setIntensity(7); // Use a value between 0 and 15 for brightness

/*
* the two for loops below may need to be modified
* depending on the ordering and orientation of your displays
*/

// the setPosition function is responsible for the ordering of displays
for(int i = 0; i < 4; i++) {
matrix.setPosition(i, i, 0); // The i'th display is at <i, 0>
}

// the setRotation function is responsible for the orientation of displays
for(int i = 0; i < 8; i++) {
matrix.setRotation(i, 1); // rotate all displays 90 degrees
}
}

void loop() {
matrix.printToDisplay(tape, wait);
}