Message scroller
Dependencies: HT1632_LedMatrix mbed-rtos mbed
main.cpp
00001 /* Copyright (c) 2012 Andrew Lindsa, MIT License 00002 * 00003 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software 00004 * and associated documentation files (the "Software"), to deal in the Software without restriction, 00005 * including without limitation the rights to use, copy, modify, merge, publish, distribute, 00006 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is 00007 * furnished to do so, subject to the following conditions: 00008 * 00009 * The above copyright notice and this permission notice shall be included in all copies or 00010 * substantial portions of the Software. 00011 * 00012 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING 00013 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 00014 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 00015 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00016 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 00017 * 00018 * Simple scrolling message display for mbed and HT1632C based LED matrix displays 00019 */ 00020 #include "mbed.h" 00021 #include "rtos.h" 00022 #include "HT1632_LedMatrix.h" 00023 00024 Serial pc(USBTX, USBRX); // tx, rx 00025 00026 // Define the onboard LEDs to use as status indicators 00027 DigitalOut led1(LED1); // Activity 00028 DigitalOut led2(LED2); // Activity, alternates with led2 00029 00030 // create object to control the LED Matrix 00031 HT1632_LedMatrix led = HT1632_LedMatrix(); 00032 00033 #define DISPDELAY 90 00034 00035 // Define the message, add blanks to front so it doesnt lose first part immediately 00036 char* msg = " The quick brown fox jumped over the lazy dog!!!"; 00037 int crtPos = 0; 00038 int msgx = 1; // position on message screen of current character, set to 1 to allow for first scroll 00039 00040 /* 00041 * This works for multiple 8x32 matrix. 00042 */ 00043 void displayScrollingLine( void const* ) 00044 { 00045 int y,xmax,ymax; 00046 led.getXYMax(&xmax,&ymax); 00047 while(true) { 00048 // shift the whole screen 6 times, one column at a time; 00049 for (int x=0; x < 6; x++) { 00050 led.scrollLeft(1,0); 00051 msgx--; 00052 // fit as much as we can on display 00053 while (!led.putChar(msgx,0,msg[crtPos])) { // zero return if it all fitted on display 00054 led.getXY(&msgx,&y); 00055 crtPos++; // we got all of the character on!! 00056 if (crtPos >= strlen(msg)) { 00057 crtPos = 0; 00058 } 00059 } 00060 led.putShadowRam(); 00061 Thread::wait(DISPDELAY); 00062 } 00063 } 00064 } 00065 00066 00067 int main() 00068 { 00069 // Define how many displays we have, older 0832 allowed vertical stacking 00070 // newer ones dont unless you want a gap between the displays. 00071 // Num horizontal displays 1 to 4, num vertical displays 1 to 4. Max 4 displays can be used. 00072 // Usable combinations are 1,1; 2,1; 3,1; 4,1; and 2,2; 1,2; 1,3; 1,4; with gaps!! 00073 led.init(2,1); 00074 pc.baud(9600); 00075 printf("LED Matrix dislay test"); 00076 led.clear(); 00077 led.setBrightness(8); 00078 00079 Thread displayTask(displayScrollingLine, NULL, osPriorityNormal, 1024 * 4); 00080 00081 // Show we are still working by alternatively flashing LED1 and LED2, once a second 00082 led1 = 0; // Working 00083 led2 = 1; // Alternate with led1 00084 while(1) { 00085 led1=!led1; 00086 led2=!led2; 00087 Thread::wait(1000); 00088 } 00089 }
Generated on Mon Aug 15 2022 09:51:42 by 1.7.2