Li Weiyi
/
LED_DZ
work fine
Embed:
(wiki syntax)
Show/hide line numbers
main.cpp
00001 // 本作品采用知识共享 署名-非商业性使用-相同方式共享 3.0 未本地化版本 许可协议进行许可 00002 // 访问 http://creativecommons.org/licenses/by-nc-sa/3.0/ 查看该许可协议 00003 // ============== 00004 00005 // 版权所有: 00006 // @老潘orz wasdpkj@hotmail.com 00007 // ============== 00008 00009 // Microduino-IDE 00010 // ============== 00011 // Microduino Getting start: 00012 // http://www.microduino.cc/download/ 00013 00014 // Microduino IDE Support: 00015 // https://github.com/wasdpkj/Microduino-IDE-Support/ 00016 00017 // ============== 00018 // Microduino wiki: 00019 // http://wiki.microduino.cc 00020 00021 // ============== 00022 // E-mail: 00023 // Kejia Pan 00024 // pankejia@microduino.cc 00025 00026 // ============== 00027 // Weibo: 00028 // @老潘orz 00029 00030 #define _MAIN_CPP 00031 #include "mbed.h" 00032 #include "MicroduinoPinNames.h" 00033 #include "Microduino_Matrix.h" 00034 #include "SomeCartoon.h" 00035 00036 uint8_t Addr[MatrixPix_X][MatrixPix_Y] = { 00037 { 64} 00038 }; 00039 00040 static uint8_t logoA[] = { //低位在前 逐行 00041 0x00, 0x66, 0x66, 0xDB, 0xDB, 0xDB, 0xDB, 0x00 00042 }; 00043 00044 static uint8_t logoB[] = { //BMP File 00045 0x42, 0x4D, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, 0x00, 0x28, 0x00, 00046 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x01, 0x00, 0x18, 0x00, 0x00, 0x00, 00047 0x00, 0x00, 0xC2, 0x00, 0x00, 0x00, 0x20, 0x2E, 0x00, 0x00, 0x20, 0x2E, 0x00, 0x00, 0x00, 0x00, 00048 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xFF, 0xEE, 0xEE, 0xEE, 00049 0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 00060 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xDD, 0x00, 0x00, 00061 }; 00062 00063 #define delay wait_ms 00064 DigitalOut myled(D13); 00065 Matrix display(Addr); 00066 AnalogIn gAnalogIn(A0); 00067 Timer g_Timer; 00068 Serial pc(D1, D0); // tx, rx 00069 00070 int main() 00071 { 00072 int i; 00073 char buf[32]; 00074 myled = 0; 00075 pc.baud(115200); 00076 g_Timer.start(); 00077 00078 for (int a = 0; a < display.getMatrixNum(); a++) { 00079 pc.printf("device add = %d", display.getDeviceAddr(a)); 00080 pc.printf(" "); 00081 } 00082 pc.printf("\r\n"); 00083 00084 myled = !myled; 00085 display.clearDisplay(); 00086 //setLedColor 00087 for (int y = 0; y < display.getHeight() * 8; y++) { 00088 for (int x = 0; x < display.getWidth() * 8; x++) { 00089 randomSeed(x); 00090 display.setLedColor(x, y, random(0, 255), random(0, 255), random(0, 255)); //x, y, r, g, b 00091 delay(20); 00092 } 00093 } 00094 delay(1000); 00095 myled = !myled; 00096 00097 //setLed 00098 display.clearDisplay(); 00099 display.setColor(255, 0, 0); 00100 for (int y = 0; y < display.getHeight() * 8; y++) { 00101 for (int x = 0; x < display.getWidth() * 8; x++) { 00102 display.setLed(x, y, true); //x, y, sta 00103 delay(5); 00104 } 00105 } 00106 delay(1000); 00107 myled = !myled; 00108 00109 //setLed 00110 display.clearDisplay(); 00111 display.setColor(0, 255, 0); 00112 for (int y = 0; y < display.getHeight() * 8; y++) { 00113 for (int x = 0; x < display.getWidth() * 8; x++) { 00114 display.setLed(x, y, true); //x, y, sta 00115 delay(5); 00116 } 00117 } 00118 delay(1000); 00119 myled = !myled; 00120 00121 //setLed 00122 display.clearDisplay(); 00123 display.setColor(0, 0, 255); 00124 for (int y = 0; y < display.getHeight() * 8; y++) { 00125 for (int x = 0; x < display.getWidth() * 8; x++) { 00126 display.setLed(x, y, true); //x, y, sta 00127 delay(5); 00128 } 00129 } 00130 delay(1000); 00131 myled = !myled; 00132 00133 display.clearDisplay(); 00134 display.setColor(0, 255, 0); 00135 display.drawBMP(0, 0, 8, 8, logoA); //x,y,w,h,data 00136 delay(2000); 00137 myled = !myled; 00138 00139 display.clearDisplay(); 00140 //Windows Bitmap (BMP) file,24bit 00141 display.drawBMP(0, 0, logoB); //x,y,data 00142 delay(2000); 00143 myled = !myled; 00144 00145 //clearColor 00146 display.clearColor(); 00147 //writeString H 00148 display.writeString("Microduino", MODE_H, 20, 0); //string, MODE, time ,y 00149 display.clearDisplay(); 00150 //writeString V 00151 display.writeString("Microduino", MODE_V, 20, 0); //string, MODE, time ,x 00152 display.clearDisplay(); 00153 myled = !myled; 00154 while(1) { 00155 display.clearDisplay(); 00156 drawCartoon01(); 00157 display.clearDisplay(); 00158 drawCartoon02(); 00159 display.clearDisplay(); 00160 drawCartoon03(); 00161 00162 display.setColor(random(0, 255), random(0, 255), random(0, 255)); 00163 display.drawBox(0, 0, 8, 8); //x,y,w,h 00164 delay(2000); 00165 display.clearDisplay(); 00166 00167 display.drawRBox(0, 0, 8, 8, 2); //x,y,w,h,r 00168 delay(2000); 00169 display.clearDisplay(); 00170 00171 display.drawFrame(0, 0, 8, 8); //x,y,w,h 00172 delay(2000); 00173 display.clearDisplay(); 00174 00175 display.drawRFrame(0, 0, 8, 8, 2); //x,y,w,h,r 00176 delay(2000); 00177 display.clearDisplay(); 00178 00179 display.drawCircle(3, 3, 3); //x,y,r 00180 delay(2000); 00181 display.clearDisplay(); 00182 00183 display.drawDisc(3, 3, 3); //x,y,r 00184 delay(2000); 00185 display.clearDisplay(); 00186 00187 display.drawLine(0, 0, 7, 7); //x,y,x1,y1 00188 delay(2000); 00189 display.clearDisplay(); 00190 00191 i = display.getStringWidth("mCookie!"); 00192 display.setColor(255, 255, 0); 00193 display.setFontMode(MODE_H); 00194 strcpy(buf, "mCookie!"); 00195 for (int a = display.getWidth() * 8; a > -i - display.getWidth() * 8; a--) { 00196 display.setCursor(a, 0); //x, y 00197 display.print(buf); 00198 delay(20); 00199 } 00200 display.clearDisplay(); 00201 00202 i = display.getStringHeight("mCookie!"); 00203 display.setColor(255, 0, 255); 00204 display.setFontMode(MODE_V); 00205 for (int a = display.getHeight() * 8; a > -i - display.getHeight() * 8; a--) { 00206 display.setCursor(0, a); //x, y 00207 display.print("mCookie!"); 00208 delay(20); 00209 } 00210 display.clearDisplay(); 00211 00212 //Print 00213 int timer = g_Timer.read_ms(); 00214 display.setColor(0, 255, 255); 00215 display.setFontMode(MODE_H); 00216 while (g_Timer.read_ms() - timer < 5000) { 00217 display.setCursor(0, 0); //x, y 00218 display.print((g_Timer.read_ms() - timer) / 100); 00219 delay(20); 00220 } 00221 display.clearDisplay(); 00222 00223 //String to char* 00224 String _buffer_data = "Analog(A0):"; 00225 //_buffer_data += analogRead(A0); 00226 _buffer_data += gAnalogIn.read_u16(); 00227 00228 char buffer_data[128]; 00229 for (int a = 0; a < 128; a++) { 00230 buffer_data[a] = NULL; 00231 } 00232 00233 for (int a = 0; a < _buffer_data.length(); a++) { 00234 buffer_data[a] = _buffer_data[a]; 00235 } 00236 00237 display.setColor(255, 255, 255); 00238 display.clearDisplay(); 00239 display.writeString(buffer_data, MODE_H, 50, 1); 00240 myled = !myled; 00241 } 00242 }
Generated on Thu Jul 14 2022 22:36:21 by 1.7.2