Display librairy manage 3 LED and a TextLCD (on, off, flash) (print message, clear)
Embed:
(wiki syntax)
Show/hide line numbers
Display.h
00001 /* import this librairies : 00002 * TextLCD.h 00003 * online compiler : https://mbed.org/compiler/#import:https://mbed.org/users/simon/code/TextLCD/;mode:lib 00004 * file.zip : http://mbed.org/users/simon/code/TextLCD/archive/44f34c09bd37.zip 00005 * 00006 * Led.h 00007 * online compiler : https://mbed.org/compiler/#import:https://mbed.org/users/us191/code/LED/;mode:lib 00008 * file.zip : https://mbed.org/users/us191/code/LED/archive/75240e7c857c.zip 00009 */ 00010 00011 #ifndef Display_H 00012 #define Display_H 00013 00014 #include "mbed.h" 00015 #include "TextLCD.h" 00016 #include "Led.h" 00017 #include "string" 00018 #include <vector> 00019 00020 00021 /** This class manage 3 LED and 1 TextLCD display. 00022 * She permit to print messages and to light or flash LED. 00023 * 00024 * @code 00025 * #include "mbed.h" 00026 * #include "Display.h" 00027 * 00028 * Display disp(p12, p13, p14, p15, p16, p5, p6, p7, p8); // greenLED, redLED, orangeLED, LCD : rs, e, d4-d7 (default : 16X2 screen) 00029 * 00030 * float delay = 3; 00031 * 00032 * 00033 * int main() { 00034 * 00035 * // print "HelloWorld !" on LCD screen and put on greenLED, flash redLED and put off orangeLED 00036 * disp.printMessage("Hello World !", Display::on, Display::flash, Display::off); 00037 * wait(delay); 00038 * 00039 * // print "coucou !" on LCD screen and put off greenLED, put on redLED and flash orangeLED 00040 * disp.printMessage("coucou !", Display::off, Display::on, Display::flash); 00041 * wait(delay); 00042 * 00043 * // print "bye bye !" on LCD screen and flash greenLED, put off redLED and put on orangeLED 00044 * disp.printMessage("bye bye !", Display::flash, Display::off, Display::on); 00045 * wait(delay); 00046 * 00047 * // clear LCD screen and shutdown 3 LED 00048 * disp.clear(); 00049 * } 00050 * @endcode 00051 */ 00052 00053 class Display { 00054 00055 public : 00056 00057 /** use by printMessage() and changeStatusLed() */ 00058 enum choiceStatusLED { 00059 on /**< put on led */ 00060 , off /**< put off led */ 00061 , flash /**< flash led */ 00062 }; 00063 00064 00065 /** Create a Display interface (default : 16X2 screen) 00066 * 00067 * @param pinGreenLED greenLED broche 00068 * @param pinRedLED redLED broche 00069 * @param pinOrangeLED orangeLED broche 00070 * @param pinLCDrs LCD Instruction/data control line 00071 * @param pinLCDe LCD Enable line (clock) 00072 * @param pinLCDd0-d3 LCD Data lines 00073 */ 00074 Display(PinName pinGreenLED, PinName pinRedLED, PinName pinOrangeLED, PinName pinLCDrs, PinName pinLCDe, 00075 PinName pinLCDd0, PinName pinLCDd1, PinName pinLCDd2, PinName pinLCDd3); 00076 00077 /** Create a Display interface 00078 * 00079 * @param pinGreenLED greenLED broche 00080 * @param pinRedLED redLED broche 00081 * @param pinOrangeLED orangeLED broche 00082 * @param pinLCDrs LCD Instruction/data control line 00083 * @param pinLCDe LCD Enable line (clock) 00084 * @param pinLCDd0-d3 LCD Data lines 00085 * @param typeScreen LCD Sets the panel size/addressing mode (default = LCD16x2) 00086 */ 00087 Display(PinName pinGreenLED, PinName pinRedLED, PinName pinOrangeLED, PinName pinLCDrs, PinName pinLCDe, 00088 PinName pinLCDd0, PinName pinLCDd1, PinName pinLCDd2, PinName pinLCDd3, TextLCD::LCDType typeScreen); 00089 00090 /** Destructor 00091 */ 00092 ~Display(void); 00093 00094 00095 /** print message on LCD screen and change status of green, red and orange LED. 00096 * all line except the last line, have to finish by CRLF. Warning : CRLF count like a character. 00097 * don't end message by CRLF. 00098 * examples :\n 00099 * "this line have to finish by CRLF\/n 00100 * and next too\/n 00101 * but not the last" 00102 * 00103 * @param message message will be display on screen 00104 * @param statusGreenLED new status of greenLED (on, off, flash) 00105 * @param statusRedLED new status of redLED (on, off, flash) 00106 * @param statusOrangeLED new status of orangeLED (on, off, flash) 00107 */ 00108 void printMessage(string message, choiceStatusLED statusGreenLED, choiceStatusLED statusRedLED, choiceStatusLED statusOrangeLED); 00109 00110 /** put off 3 LED and clear LCD screen 00111 */ 00112 void clear(void); 00113 00114 00115 protected : 00116 00117 /* 3 led manage by current object */ 00118 Led _greenLED, _redLED, _orangeLED; 00119 /* LCD screen manage by current object */ 00120 TextLCD _lcd; 00121 00122 /* use by changeStatusLed() */ 00123 enum choiceLED { 00124 green /*< choice greenLED */ 00125 , red /*< choice redLED */ 00126 , orange /*< choice orangeLED */ 00127 }; 00128 00129 00130 00131 /* change led status to statusLED 00132 * use by printMessage() 00133 * 00134 * @param led the led (green, red, orange) 00135 * @param statusLED new status (on, off, flash) 00136 */ 00137 void changeStatusLED(choiceLED led, choiceStatusLED statusLED); 00138 00139 /* put off 3 LED 00140 * use by clear() 00141 */ 00142 void shutdownLED(void); 00143 00144 /* clear LCD screen 00145 * use by clear() 00146 */ 00147 void cls(void); 00148 00149 /* check if this message can be display correctly on LCD screen 00150 * use by printMessage() 00151 * 00152 * @param message the message to be verified 00153 * @return 00154 * true if message is ok 00155 * flase else 00156 */ 00157 bool checkMessage(string message); 00158 00159 /* calcul number of '\n' 00160 * use by checkMessage() 00161 * 00162 * @param message the message to be analyse 00163 * @return number of '\n' 00164 */ 00165 int calculNbCRLF(string message); 00166 00167 /* return vector of all line message 00168 * use by checkMessage() 00169 * 00170 * @param message the message to be cut 00171 * @return a vector which contains a line of the message by entry 00172 */ 00173 vector<string> subAllLine(string message); 00174 00175 }; 00176 00177 #endif // Display_H
Generated on Mon Aug 8 2022 14:17:56 by 1.7.2