Created
January 15, 2015 20:38
-
-
Save stephpalm/2f5226e0621201823195 to your computer and use it in GitHub Desktop.
Scrolling text
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// scrolltext demo for Adafruit RGBmatrixPanel library. | |
// Demonstrates double-buffered animation on our 16x32 RGB LED matrix: | |
// http://www.adafruit.com/products/420 | |
// Written by Limor Fried/Ladyada & Phil Burgess/PaintYourDragon | |
// for Adafruit Industries. | |
// BSD license, all text above must be included in any redistribution. | |
#if defined(SPARK) | |
#include "Adafruit_mfGFX/Adafruit_mfGFX.h" // Core graphics library | |
#include "RGBmatrixPanel/RGBmatrixPanel.h" // Hardware-specific library | |
#include "math.h" | |
#else | |
#include <avr/pgmspace.h> | |
#include <Adafruit_GFX.h> // Core graphics library | |
#include <RGBmatrixPanel.h> // Hardware-specific library | |
#endif | |
#if defined(SPARK) | |
#define CLK D6 | |
#define OE D7 | |
#define LAT A4 | |
#define A A0 | |
#define B A1 | |
#define C A2 | |
#define pgm_read_word(addr) (*(const unsigned short *)(addr)) | |
#else | |
#define CLK 8 // MUST be on PORTB! (Use pin 11 on Mega) | |
#define LAT A3 | |
#define OE 9 | |
#define A A0 | |
#define B A1 | |
#define C A2 | |
#endif | |
// Last parameter = 'true' enables double-buffering, for flicker-free, | |
// buttery smooth animation. Note that NOTHING WILL SHOW ON THE DISPLAY | |
// until the first call to swapBuffers(). This is normal. | |
RGBmatrixPanel matrix(A, B, C, CLK, LAT, OE, true); | |
// Double-buffered mode consumes nearly all the RAM available on the | |
// Arduino Uno -- only a handful of free bytes remain. Even the | |
// following string needs to go in PROGMEM: | |
String displayText = String("Happy Thanksgiving"); | |
//const char str[] PROGMEM = "Happy Thanksgiving!"; | |
int textX = matrix.width(), | |
textMin = displayText.length() * -12, | |
hue = 0; | |
int8_t ball[3][4] = { | |
{ 3, 0, 1, 1 }, // Initial X,Y pos & velocity for 3 bouncy balls | |
{ 17, 15, 1, -1 }, | |
{ 27, 4, -1, 1 } | |
}; | |
static const uint16_t PROGMEM ballcolor[3] = { | |
0x0080, // Green=1 | |
0x0002, // Blue=1 | |
0x1000 // Red=1 | |
}; | |
void setup() { | |
Spark.function("setText", setTextFn); | |
matrix.begin(); | |
matrix.setTextWrap(false); // Allow text to run off right edge | |
matrix.setTextSize(2); | |
} | |
int setTextFn(String command) { | |
displayText = command; | |
textMin = displayText.length() * -12; | |
} | |
void loop() { | |
byte i; | |
// Clear background | |
matrix.fillScreen(0); | |
// Bounce three balls around | |
// for(i=0; i<3; i++) { | |
// Draw 'ball' | |
// matrix.fillCircle(ball[i][0], ball[i][1], 5, pgm_read_word(&ballcolor[i])); | |
// Update X, Y position | |
// ball[i][0] += ball[i][2]; | |
// ball[i][1] += ball[i][3]; | |
// Bounce off edges | |
// if((ball[i][0] == 0) || (ball[i][0] == (matrix.width() - 1))) | |
// ball[i][2] *= -1; | |
// if((ball[i][1] == 0) || (ball[i][1] == (matrix.height() - 1))) | |
// ball[i][3] *= -1; | |
// } | |
// Draw big scrolly text on top | |
matrix.setTextColor(matrix.ColorHSV(hue, 255, 255, true)); | |
matrix.setCursor(textX, 1); | |
matrix.print(F(displayText.c_str())); | |
// Move text left (w/wrap), increase hue | |
if((--textX) < textMin) textX = matrix.width(); | |
hue += 7; | |
if(hue >= 1536) hue -= 1536; | |
// Update display | |
matrix.swapBuffers(false); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment