Message scroller

Dependencies:   HT1632_LedMatrix mbed-rtos mbed

Committer:
SomeRandomBloke
Date:
Wed Nov 28 22:01:37 2012 +0000
Revision:
3:91c74da4b95a
Parent:
2:f6d3011fb5bb
Child:
4:879975f891d0
2 displays

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