Message scroller

Dependencies:   HT1632_LedMatrix mbed-rtos mbed

Committer:
SomeRandomBloke
Date:
Wed Nov 28 22:05:05 2012 +0000
Revision:
4:879975f891d0
Parent:
3:91c74da4b95a
update

Who changed what in which revision?

UserRevisionLine numberNew contents of line
SomeRandomBloke 4:879975f891d0 1 /* Copyright (c) 2012 Andrew Lindsa, MIT License
SomeRandomBloke 4:879975f891d0 2 *
SomeRandomBloke 4:879975f891d0 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
SomeRandomBloke 4:879975f891d0 4 * and associated documentation files (the "Software"), to deal in the Software without restriction,
SomeRandomBloke 4:879975f891d0 5 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
SomeRandomBloke 4:879975f891d0 6 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
SomeRandomBloke 4:879975f891d0 7 * furnished to do so, subject to the following conditions:
SomeRandomBloke 4:879975f891d0 8 *
SomeRandomBloke 4:879975f891d0 9 * The above copyright notice and this permission notice shall be included in all copies or
SomeRandomBloke 4:879975f891d0 10 * substantial portions of the Software.
SomeRandomBloke 4:879975f891d0 11 *
SomeRandomBloke 4:879975f891d0 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
SomeRandomBloke 4:879975f891d0 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
SomeRandomBloke 4:879975f891d0 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
SomeRandomBloke 4:879975f891d0 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
SomeRandomBloke 4:879975f891d0 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
SomeRandomBloke 4:879975f891d0 17 *
SomeRandomBloke 4:879975f891d0 18 * Simple scrolling message display for mbed and HT1632C based LED matrix displays
SomeRandomBloke 4:879975f891d0 19 */
SomeRandomBloke 0:5438c56c3e4c 20 #include "mbed.h"
SomeRandomBloke 1:fecc093f43d4 21 #include "rtos.h"
SomeRandomBloke 2:f6d3011fb5bb 22 #include "HT1632_LedMatrix.h"
SomeRandomBloke 0:5438c56c3e4c 23
SomeRandomBloke 0:5438c56c3e4c 24 Serial pc(USBTX, USBRX); // tx, rx
SomeRandomBloke 0:5438c56c3e4c 25
SomeRandomBloke 0:5438c56c3e4c 26 // Define the onboard LEDs to use as status indicators
SomeRandomBloke 0:5438c56c3e4c 27 DigitalOut led1(LED1); // Activity
SomeRandomBloke 0:5438c56c3e4c 28 DigitalOut led2(LED2); // Activity, alternates with led2
SomeRandomBloke 0:5438c56c3e4c 29
SomeRandomBloke 0:5438c56c3e4c 30 // create object to control the LED Matrix
SomeRandomBloke 0:5438c56c3e4c 31 HT1632_LedMatrix led = HT1632_LedMatrix();
SomeRandomBloke 0:5438c56c3e4c 32
SomeRandomBloke 0:5438c56c3e4c 33 #define DISPDELAY 90
SomeRandomBloke 0:5438c56c3e4c 34
SomeRandomBloke 0:5438c56c3e4c 35 // Define the message, add blanks to front so it doesnt lose first part immediately
SomeRandomBloke 0:5438c56c3e4c 36 char* msg = " The quick brown fox jumped over the lazy dog!!!";
SomeRandomBloke 0:5438c56c3e4c 37 int crtPos = 0;
SomeRandomBloke 0:5438c56c3e4c 38 int msgx = 1; // position on message screen of current character, set to 1 to allow for first scroll
SomeRandomBloke 0:5438c56c3e4c 39
SomeRandomBloke 0:5438c56c3e4c 40 /*
SomeRandomBloke 0:5438c56c3e4c 41 * This works for multiple 8x32 matrix.
SomeRandomBloke 0:5438c56c3e4c 42 */
SomeRandomBloke 0:5438c56c3e4c 43 void displayScrollingLine( void const* )
SomeRandomBloke 0:5438c56c3e4c 44 {
SomeRandomBloke 0:5438c56c3e4c 45 int y,xmax,ymax;
SomeRandomBloke 0:5438c56c3e4c 46 led.getXYMax(&xmax,&ymax);
SomeRandomBloke 0:5438c56c3e4c 47 while(true) {
SomeRandomBloke 0:5438c56c3e4c 48 // shift the whole screen 6 times, one column at a time;
SomeRandomBloke 0:5438c56c3e4c 49 for (int x=0; x < 6; x++) {
SomeRandomBloke 0:5438c56c3e4c 50 led.scrollLeft(1,0);
SomeRandomBloke 0:5438c56c3e4c 51 msgx--;
SomeRandomBloke 0:5438c56c3e4c 52 // fit as much as we can on display
SomeRandomBloke 0:5438c56c3e4c 53 while (!led.putChar(msgx,0,msg[crtPos])) { // zero return if it all fitted on display
SomeRandomBloke 0:5438c56c3e4c 54 led.getXY(&msgx,&y);
SomeRandomBloke 0:5438c56c3e4c 55 crtPos++; // we got all of the character on!!
SomeRandomBloke 0:5438c56c3e4c 56 if (crtPos >= strlen(msg)) {
SomeRandomBloke 0:5438c56c3e4c 57 crtPos = 0;
SomeRandomBloke 0:5438c56c3e4c 58 }
SomeRandomBloke 0:5438c56c3e4c 59 }
SomeRandomBloke 0:5438c56c3e4c 60 led.putShadowRam();
SomeRandomBloke 0:5438c56c3e4c 61 Thread::wait(DISPDELAY);
SomeRandomBloke 0:5438c56c3e4c 62 }
SomeRandomBloke 0:5438c56c3e4c 63 }
SomeRandomBloke 0:5438c56c3e4c 64 }
SomeRandomBloke 0:5438c56c3e4c 65
SomeRandomBloke 0:5438c56c3e4c 66
SomeRandomBloke 0:5438c56c3e4c 67 int main()
SomeRandomBloke 0:5438c56c3e4c 68 {
SomeRandomBloke 0:5438c56c3e4c 69 // Define how many displays we have, older 0832 allowed vertical stacking
SomeRandomBloke 0:5438c56c3e4c 70 // newer ones dont unless you want a gap between the displays.
SomeRandomBloke 0:5438c56c3e4c 71 // Num horizontal displays 1 to 4, num vertical displays 1 to 4. Max 4 displays can be used.
SomeRandomBloke 0:5438c56c3e4c 72 // 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 73 led.init(2,1);
SomeRandomBloke 0:5438c56c3e4c 74 pc.baud(9600);
SomeRandomBloke 0:5438c56c3e4c 75 printf("LED Matrix dislay test");
SomeRandomBloke 0:5438c56c3e4c 76 led.clear();
SomeRandomBloke 0:5438c56c3e4c 77 led.setBrightness(8);
SomeRandomBloke 0:5438c56c3e4c 78
SomeRandomBloke 0:5438c56c3e4c 79 Thread displayTask(displayScrollingLine, NULL, osPriorityNormal, 1024 * 4);
SomeRandomBloke 0:5438c56c3e4c 80
SomeRandomBloke 0:5438c56c3e4c 81 // Show we are still working by alternatively flashing LED1 and LED2, once a second
SomeRandomBloke 0:5438c56c3e4c 82 led1 = 0; // Working
SomeRandomBloke 0:5438c56c3e4c 83 led2 = 1; // Alternate with led1
SomeRandomBloke 0:5438c56c3e4c 84 while(1) {
SomeRandomBloke 0:5438c56c3e4c 85 led1=!led1;
SomeRandomBloke 0:5438c56c3e4c 86 led2=!led2;
SomeRandomBloke 0:5438c56c3e4c 87 Thread::wait(1000);
SomeRandomBloke 0:5438c56c3e4c 88 }
SomeRandomBloke 0:5438c56c3e4c 89 }