Message scroller

Dependencies:   HT1632_LedMatrix mbed-rtos mbed

Committer:
SomeRandomBloke
Date:
Wed Nov 28 16:46:58 2012 +0000
Revision:
0:5438c56c3e4c
Child:
1:fecc093f43d4
Example scrolling message

Who changed what in which revision?

UserRevisionLine numberNew contents of line
SomeRandomBloke 0:5438c56c3e4c 1 // Simple scrolling message display for mbed and HT1632C based LED matrix displays
SomeRandomBloke 0:5438c56c3e4c 2
SomeRandomBloke 0:5438c56c3e4c 3 #include "mbed.h"
SomeRandomBloke 0:5438c56c3e4c 4 #include <HT1632_LedMatrix.h>
SomeRandomBloke 0:5438c56c3e4c 5
SomeRandomBloke 0:5438c56c3e4c 6 Serial pc(USBTX, USBRX); // tx, rx
SomeRandomBloke 0:5438c56c3e4c 7
SomeRandomBloke 0:5438c56c3e4c 8 // Define the onboard LEDs to use as status indicators
SomeRandomBloke 0:5438c56c3e4c 9 DigitalOut led1(LED1); // Activity
SomeRandomBloke 0:5438c56c3e4c 10 DigitalOut led2(LED2); // Activity, alternates with led2
SomeRandomBloke 0:5438c56c3e4c 11
SomeRandomBloke 0:5438c56c3e4c 12 // create object to control the LED Matrix
SomeRandomBloke 0:5438c56c3e4c 13 HT1632_LedMatrix led = HT1632_LedMatrix();
SomeRandomBloke 0:5438c56c3e4c 14
SomeRandomBloke 0:5438c56c3e4c 15 #define DISPDELAY 90
SomeRandomBloke 0:5438c56c3e4c 16
SomeRandomBloke 0:5438c56c3e4c 17 // Define the message, add blanks to front so it doesnt lose first part immediately
SomeRandomBloke 0:5438c56c3e4c 18 char* msg = " The quick brown fox jumped over the lazy dog!!!";
SomeRandomBloke 0:5438c56c3e4c 19 int crtPos = 0;
SomeRandomBloke 0:5438c56c3e4c 20 int msgx = 1; // position on message screen of current character, set to 1 to allow for first scroll
SomeRandomBloke 0:5438c56c3e4c 21
SomeRandomBloke 0:5438c56c3e4c 22 /*
SomeRandomBloke 0:5438c56c3e4c 23 * This works for multiple 8x32 matrix.
SomeRandomBloke 0:5438c56c3e4c 24 */
SomeRandomBloke 0:5438c56c3e4c 25 void displayScrollingLine( void const* )
SomeRandomBloke 0:5438c56c3e4c 26 {
SomeRandomBloke 0:5438c56c3e4c 27 int y,xmax,ymax;
SomeRandomBloke 0:5438c56c3e4c 28 led.getXYMax(&xmax,&ymax);
SomeRandomBloke 0:5438c56c3e4c 29 while(true) {
SomeRandomBloke 0:5438c56c3e4c 30 // shift the whole screen 6 times, one column at a time;
SomeRandomBloke 0:5438c56c3e4c 31 for (int x=0; x < 6; x++) {
SomeRandomBloke 0:5438c56c3e4c 32 led.scrollLeft(1,0);
SomeRandomBloke 0:5438c56c3e4c 33 msgx--;
SomeRandomBloke 0:5438c56c3e4c 34 // fit as much as we can on display
SomeRandomBloke 0:5438c56c3e4c 35 while (!led.putChar(msgx,0,msg[crtPos])) { // zero return if it all fitted on display
SomeRandomBloke 0:5438c56c3e4c 36 led.getXY(&msgx,&y);
SomeRandomBloke 0:5438c56c3e4c 37 crtPos++; // we got all of the character on!!
SomeRandomBloke 0:5438c56c3e4c 38 if (crtPos >= strlen(msg)) {
SomeRandomBloke 0:5438c56c3e4c 39 crtPos = 0;
SomeRandomBloke 0:5438c56c3e4c 40 }
SomeRandomBloke 0:5438c56c3e4c 41 }
SomeRandomBloke 0:5438c56c3e4c 42 led.putShadowRam();
SomeRandomBloke 0:5438c56c3e4c 43 Thread::wait(DISPDELAY);
SomeRandomBloke 0:5438c56c3e4c 44 }
SomeRandomBloke 0:5438c56c3e4c 45 }
SomeRandomBloke 0:5438c56c3e4c 46 }
SomeRandomBloke 0:5438c56c3e4c 47
SomeRandomBloke 0:5438c56c3e4c 48
SomeRandomBloke 0:5438c56c3e4c 49 int main()
SomeRandomBloke 0:5438c56c3e4c 50 {
SomeRandomBloke 0:5438c56c3e4c 51 // Define how many displays we have, older 0832 allowed vertical stacking
SomeRandomBloke 0:5438c56c3e4c 52 // newer ones dont unless you want a gap between the displays.
SomeRandomBloke 0:5438c56c3e4c 53 // Num horizontal displays 1 to 4, num vertical displays 1 to 4. Max 4 displays can be used.
SomeRandomBloke 0:5438c56c3e4c 54 // Usable combinations are 1,1; 2,1; 3,1; 4,1; and 2,2; 1,2; 1,3; 1,4; with gaps!!
SomeRandomBloke 0:5438c56c3e4c 55 led.init(1,1);
SomeRandomBloke 0:5438c56c3e4c 56 pc.baud(9600);
SomeRandomBloke 0:5438c56c3e4c 57 printf("LED Matrix dislay test");
SomeRandomBloke 0:5438c56c3e4c 58 led.clear();
SomeRandomBloke 0:5438c56c3e4c 59 led.setBrightness(8);
SomeRandomBloke 0:5438c56c3e4c 60
SomeRandomBloke 0:5438c56c3e4c 61 Thread displayTask(displayScrollingLine, NULL, osPriorityNormal, 1024 * 4);
SomeRandomBloke 0:5438c56c3e4c 62
SomeRandomBloke 0:5438c56c3e4c 63 // Show we are still working by alternatively flashing LED1 and LED2, once a second
SomeRandomBloke 0:5438c56c3e4c 64 led1 = 0; // Working
SomeRandomBloke 0:5438c56c3e4c 65 led2 = 1; // Alternate with led1
SomeRandomBloke 0:5438c56c3e4c 66 while(1) {
SomeRandomBloke 0:5438c56c3e4c 67 led1=!led1;
SomeRandomBloke 0:5438c56c3e4c 68 led2=!led2;
SomeRandomBloke 0:5438c56c3e4c 69 Thread::wait(1000);
SomeRandomBloke 0:5438c56c3e4c 70 }
SomeRandomBloke 0:5438c56c3e4c 71 }