Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
00001 /** 00002 * New filename: Main.cpp 00003 * @filename : epd1in54-demo.ino 00004 * @brief : 1.54inch e-paper display demo 00005 * @author : Yehui from Waveshare 00006 * 00007 * Copyright (C) Waveshare September 5 2017 00008 * 00009 * Permission is hereby granted, free of charge, to any person obtaining a copy 00010 * of this software and associated documnetation files (the "Software"), to deal 00011 * in the Software without restriction, including without limitation the rights 00012 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00013 * copies of the Software, and to permit persons to whom the Software is 00014 * furished to do so, subject to the following conditions: 00015 * 00016 * The above copyright notice and this permission notice shall be included in 00017 * all copies or substantial portions of the Software. 00018 * 00019 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00020 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00021 * FITNESS OR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00022 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00023 * LIABILITY WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00024 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00025 * THE SOFTWARE. 00026 */ 00027 00028 // The 1.54 Incht E-paper Waveshare software is modified to work on a Kl25Z 00029 // epaper --------- KL25X 00030 // BUSY ----------- PTA13 00031 // RST ------------ PTA17 00032 // DC ------------- PTD5 00033 // CS ------------- PTD0 00034 // CLK ------------ PTD1 00035 // DIN ------------ PTD2 00036 // GND ------------ PTE3 00037 // 3.3V ----------- PTD9 00038 // NO connection with PTD3 00039 00040 #include "mbed.h" 00041 #include "epd1in54.h" 00042 #include "epdpaint.h" 00043 #include "epdif.h" 00044 #include "imagedata.h" 00045 00046 #define COLORED 0 00047 #define UNCOLORED 1 00048 00049 Serial pc(USBTX, USBRX, 115200); 00050 00051 DigitalOut reset_pin(PTA17); 00052 DigitalOut dc_pin(PTD5); 00053 DigitalOut cs_pin(PTD0); 00054 DigitalIn busy_pin(PTA13, PullNone); 00055 SPI epaper(PTD2,PTD3,PTD1); //MOSI, MISO, CLK 00056 DigitalOut myled(LED2); 00057 Timer timer; 00058 00059 /** 00060 * Due to RAM not enough in Arduino UNO, a frame buffer is not allowed. 00061 * In this case, a smaller image buffer is allocated and you have to 00062 * update a partial display several times. 00063 * 1 byte = 8 pixels, therefore you have to set 8*N pixels at a time. 00064 */ 00065 unsigned char image[1024]; 00066 Paint paint(image, 0, 0); // width should be the multiple of 8 00067 Epd epd; 00068 unsigned long time_start_ms; 00069 unsigned long time_now_s; 00070 00071 void setup() 00072 { 00073 // put your setup code here, to run once: 00074 if (epd.Init(lut_full_update) != 0) { 00075 pc.printf("e-Paper init failed !!!"); 00076 return; 00077 } 00078 00079 /** 00080 * there are 2 memory areas embedded in the e-paper display 00081 * and once the display is refreshed, the memory area will be auto-toggled, 00082 * i.e. the next action of SetFrameMemory will set the other memory area 00083 * therefore you have to clear the frame memory twice. 00084 */ 00085 00086 epd.ClearFrameMemory(0xFF); // bit set = white, bit reset = black 00087 epd.DisplayFrame(); 00088 epd.ClearFrameMemory(0xFF); // bit set = white, bit reset = black 00089 epd.DisplayFrame(); 00090 00091 paint.SetRotate(ROTATE_0); 00092 paint.SetWidth(200); 00093 paint.SetHeight(24); 00094 00095 /* For simplicity, the arguments are explicit numerical coordinates */ 00096 00097 paint.Clear(COLORED); 00098 paint.DrawStringAt(30, 4, "Hello world!", &Font16, UNCOLORED); 00099 epd.SetFrameMemory(paint.GetImage(), 0, 10, paint.GetWidth(), paint.GetHeight()); 00100 00101 paint.Clear(UNCOLORED); 00102 paint.DrawStringAt(30, 4, "e-Paper Demo", &Font16, COLORED); 00103 epd.SetFrameMemory(paint.GetImage(), 0, 30, paint.GetWidth(), paint.GetHeight()); 00104 00105 paint.SetWidth(64); 00106 paint.SetHeight(64); 00107 00108 pc.printf("Rectangle \n\r"); 00109 paint.Clear(UNCOLORED); 00110 paint.DrawRectangle(0, 0, 40, 50, COLORED); 00111 paint.DrawLine(0, 0, 40, 50, COLORED); 00112 paint.DrawLine(40, 0, 0, 50, COLORED); 00113 epd.SetFrameMemory(paint.GetImage(), 16, 60, paint.GetWidth(), paint.GetHeight()); 00114 00115 paint.Clear(UNCOLORED); 00116 paint.DrawCircle(32, 32, 30, COLORED); 00117 epd.SetFrameMemory(paint.GetImage(), 120, 60, paint.GetWidth(), paint.GetHeight()); 00118 00119 paint.Clear(UNCOLORED); 00120 paint.DrawFilledRectangle(0, 0, 40, 50, COLORED); 00121 epd.SetFrameMemory(paint.GetImage(), 16, 130, paint.GetWidth(), paint.GetHeight()); 00122 00123 paint.Clear(UNCOLORED); 00124 paint.DrawFilledCircle(32, 32, 30, COLORED); 00125 epd.SetFrameMemory(paint.GetImage(), 120, 130, paint.GetWidth(), paint.GetHeight()); 00126 epd.DisplayFrame(); 00127 00128 wait_ms(2000); 00129 00130 if (epd.Init(lut_partial_update) != 0) { 00131 pc.printf("e-Paper init failed"); 00132 return; 00133 } 00134 00135 /** 00136 * there are 2 memory areas embedded in the e-paper display 00137 * and once the display is refreshed, the memory area will be auto-toggled, 00138 * i.e. the next action of SetFrameMemory will set the other memory area 00139 * therefore you have to set the frame memory and refresh the display twice. 00140 */ 00141 epd.SetFrameMemory(IMAGE_DATA); 00142 epd.DisplayFrame(); 00143 epd.SetFrameMemory(IMAGE_DATA); 00144 epd.DisplayFrame(); 00145 00146 time_start_ms = timer.read_ms(); 00147 } 00148 00149 void loop() 00150 { 00151 // put your main code here, to run repeatedly: 00152 time_now_s = (timer.read_ms() - time_start_ms) / 1000; 00153 char time_string[] = {'0', '0', ':', '0', '0', '\0'}; 00154 time_string[0] = time_now_s / 60 / 10 + '0'; 00155 time_string[1] = time_now_s / 60 % 10 + '0'; 00156 time_string[3] = time_now_s % 60 / 10 + '0'; 00157 time_string[4] = time_now_s % 60 % 10 + '0'; 00158 00159 paint.SetWidth(32); 00160 paint.SetHeight(96); 00161 paint.SetRotate(ROTATE_270); 00162 00163 paint.Clear(UNCOLORED); 00164 paint.DrawStringAt(0, 4, time_string, &Font24, COLORED); 00165 epd.SetFrameMemory(paint.GetImage(), 80, 72, paint.GetWidth(), paint.GetHeight()); 00166 epd.DisplayFrame(); 00167 } 00168 00169 int main() 00170 { 00171 timer.start(); 00172 pc.printf("\n\r\n\r\n\rWaveshare 1.54 inch e-Paper start\n\r"); 00173 setup(); 00174 00175 while(1) { 00176 loop(); 00177 myled = 1; 00178 wait(0.5); 00179 myled = 0; 00180 wait(0.5); 00181 } 00182 00183 } 00184
Generated on Thu Jul 14 2022 13:24:40 by
1.7.2