Professional Documents
Culture Documents
*----------------------------------------------------------------------------------
----
DMD.h - Function and support library for the Freetronics DMD, a 512 LED matrix
display
panel arranged in a 32 x 16 layout.
Copyright (C) 2011 Marc Alexander (info <at> freetronics <dot> com)
Note that the DMD library uses the SPI port for the fastest, low overhead writing
to the
display. Keep an eye on conflicts if there are any other devices running from the
same
SPI port, and that the chip select on those devices is correctly set to be
inactive
when the DMD is being written to.
---
This program is free software: you can redistribute it and/or modify it under the
terms
of the version 3 GNU General Public License as published by the Free Software
Foundation.
This program is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this
program.
If not, see <http://www.gnu.org/licenses/>.
-----------------------------------------------------------------------------------
---*/
#ifndef DMD_H_
#define DMD_H_
//SPI library must be included for the SPI scanning/connection method to the DMD
#include "pins_arduino.h"
#include <avr/pgmspace.h>
#include <SPI.h>
//
###################################################################################
###################################
//
###################################################################################
###################################
#warning CHANGE THESE TO SEMI-ADJUSTABLE PIN DEFS!
//Arduino pins used for the display connection
#define PIN_DMD_nOE 9 // D9 active low Output Enable, setting this low
lights all the LEDs in the selected rows. Can pwm it at very high frequency for
brightness control.
#define PIN_DMD_A 6 // D6
#define PIN_DMD_B 7 // D7
#define PIN_DMD_CLK 13 // D13_SCK is SPI Clock if SPI is used
#define PIN_DMD_SCLK 8 // D8
#define PIN_DMD_R_DATA 11 // D11_MOSI is SPI Master Out if SPI is used
//Define this chip select pin that the Ethernet W5100 IC or other SPI device uses
//if it is in use during a DMD scan request then scanDisplayBySPI() will exit
without conflict! (and skip that scan)
#define PIN_OTHER_SPI_nCS 10
//
###################################################################################
###################################
//
###################################################################################
###################################
//drawTestPattern Patterns
#define PATTERN_ALT_0 0
#define PATTERN_ALT_1 1
#define PATTERN_STRIPE_0 2
#define PATTERN_STRIPE_1 3
// Font Indices
#define FONT_LENGTH 0
#define FONT_FIXED_WIDTH 2
#define FONT_HEIGHT 3
#define FONT_FIRST_CHAR 4
#define FONT_CHAR_COUNT 5
#define FONT_WIDTH_TABLE 6
//Set or clear a pixel at the x and y location (0,0 is the top left corner)
void writePixel( unsigned int bX, unsigned int bY, byte bGraphicsMode, byte
bPixel );
//Draw a string
void drawString( int bX, int bY, const char* bChars, byte length, byte
bGraphicsMode);
//Scan the dot matrix LED panel display, from the RAM mirror out to the display
hardware.
//Call 4 times to scan the whole display which is made up of 4 interleaved rows
within the 16 total rows.
//Insert the calls to this function into the main loop for the highest call rate,
or from a timer interrupt
void scanDisplayBySPI();
private:
void drawCircleSub( int cx, int cy, int x, int y, byte bGraphicsMode );
//Mirror of DMD pixels in RAM, ready to be clocked out by the main loop or high
speed timer calls
byte *bDMDScreenRAM;
//Marquee values
char marqueeText[256];
byte marqueeLength;
int marqueeWidth;
int marqueeHeight;
int marqueeOffsetX;
int marqueeOffsetY;
//Display information
byte DisplaysWide;
byte DisplaysHigh;
byte DisplaysTotal;
int row1, row2, row3;
//scanning pointer into bDMDScreenRAM, setup init @ 48 for the first valid scan
volatile byte bDMDByte;
};
#endif /* DMD_H_ */