acid-drop- Hacking the planet from a LilyGo T-Deck using custom firmware |
git clone git://git.acid.vegas/acid-drop.git |
Log | Files | Refs | Archive | README | LICENSE |
Floyd_Steinberg.ino (7872B)
1 // Display grey-scale images on a Monchrome ePaper display using 2 // Floyd-Steinberg dithering 3 // https://en.wikipedia.org/wiki/Floyd%E2%80%93Steinberg_dithering 4 5 // Example created by Bodmer 31/3/18 for TFT_eSPI library: 6 // https://github.com/Bodmer/TFT_eSPI 7 // Select the ePaper setup in library's "User_Setup_Select.h" file 8 9 // This sketch supports Waveshare 2 colour ePaper displays 10 // https://www.waveshare.com/product/modules/oleds-lcds/e-paper.htm 11 12 // Test images are in the Data folder with sketch (press Ctrl+k) 13 // Upload using the Tools menu "ESP8266 Sketch Data Upload" option 14 15 /////////////////////////////////////////////////////////////////// 16 // For ESP8266 connect as follows: // 17 // Display 3.3V to NodeMCU 3V3 // 18 // Display GND to NodeMCU GND // 19 // // 20 // Display GPIO NodeMCU pin // 21 // BUSY 5 D1 // 22 // RESET 4 D2 // 23 // DC 0 D3 // 24 // CS 2 D4 // 25 // CLK 14 D5 // 26 // D6 (MISO not connected to display) // 27 // DIN 13 D7 // 28 // // 29 // Note: Pin allocations for the ePaper signals are defined in // 30 // ePaper library's epdif.h file, above are the default pins // 31 /////////////////////////////////////////////////////////////////// 32 33 // READ THIS READ THIS READ THIS READ THIS READ THIS READ THIS 34 // Install the ePaper library for your own display size and type 35 // from here: 36 // https://github.com/Bodmer/EPD_Libraries 37 38 // The following is for the Waveshare 2.7" colour ePaper display 39 // include <epd?in?.h> where ?.?? is screen size in inches 40 #include <epd2in7.h> // Screen specific library 41 //#include <epd2in13.h> 42 43 Epd ePaper; // Create an instance ePaper 44 45 #include <TFT_eSPI.h> // Graphics library and Sprite class 46 47 TFT_eSPI glc = TFT_eSPI(); // Invoke the graphics library class 48 TFT_eSprite frame = TFT_eSprite(&glc); // Invoke the Sprite class for the image frame buffer 49 50 #define INK COLORED // Black ink 51 #define PAPER UNCOLORED // 'paper' background colour 52 53 uint16_t epd_width = EPD_WIDTH; // Set the initial values, these are swapped 54 uint16_t epd_height = EPD_HEIGHT; // in different landscape/portrait rotations 55 // so call frame.width() or frame.height() to get new values 56 57 #define EPD_BUFFER 1 // Label for the black frame buffer 1 58 59 uint8_t* framePtr = NULL; // Pointer for the black frame buffer 60 61 #include "EPD_Support.h" // Include sketch EPD support functions last! 62 63 int8_t limit = 5; // Limit the number of loops before halting 64 //------------------------------------------------------------------------------------ 65 // Setup 66 //------------------------------------------------------------------------------------ 67 void setup() { 68 69 Serial.begin(250000); // Used for messages 70 71 // Initialise the ePaper library 72 if (ePaper.Init(INIT_LUT) != 0) { 73 Serial.print("ePaper init failed"); 74 while (1) yield(); // Wait here until re-boot 75 } 76 77 Serial.println("\r\n ePaper initialisation OK"); 78 79 // Initialise the SPIFFS filing system 80 if (!SPIFFS.begin()) { 81 Serial.println("SPIFFS initialisation failed!"); 82 while (1) yield(); // Stay here twiddling thumbs 83 } 84 85 Serial.println(" SPIFFS initialisation OK"); 86 87 frame.setColorDepth(1); // Must set the bits per pixel to 1 for ePaper displays 88 // Set bit depth BEFORE creating Sprite, default is 16! 89 90 // Create a frame buffer in RAM of defined size and save the pointer to it 91 // RAM needed is about (EPD_WIDTH * EPD_HEIGHT)/8 , ~5000 bytes for 200 x 200 pixels 92 // Note: always create the Sprite before setting the Sprite rotation 93 framePtr = (uint8_t*) frame.createSprite(EPD_WIDTH, EPD_HEIGHT); 94 95 Serial.println("\r\nInitialisation done."); 96 97 listFiles(); // List all the files in the SPIFFS 98 } 99 100 //------------------------------------------------------------------------------------ 101 // Loop 102 //------------------------------------------------------------------------------------ 103 void loop() { 104 105 frame.setRotation(random(4)); // Set the rotation to 0, 1, 2 or 3 ( 1 & 3 = landscape) 106 107 frame.fillSprite(PAPER); 108 109 // Draw 8 bit grey-scale bitmap using Floyd-Steinberg dithering at x,y 110 // /File name x y 111 //drawFSBmp("/TestCard.bmp", 0, 0); // 176 x 264 pixels 112 113 drawFSBmp("/Tiger.bmp", (frame.width()-176)/2, (frame.height()-234)/2); // 176 x 234 pixels 114 115 updateDisplay(); // Send image to display and refresh 116 117 delay(5000); 118 119 frame.fillSprite(PAPER); // Fill frame with white 120 121 // Draw circle in frame buffer (x, y, r, color) in centre of screen 122 frame.drawCircle(frame.width()/2, frame.height()/2, frame.width()/6, INK); 123 124 // Draw diagonal lines 125 frame.drawLine(0 , 0, frame.width()-1, frame.height()-1, INK); 126 frame.drawLine(0 , frame.height()-1, frame.width()-1, 0, INK); 127 128 updateDisplay(); // Send image to display and refresh 129 130 delay(3000); 131 132 // Run a rotation test 133 rotateTest(); 134 135 // Put screen to sleep to save power (if wanted) 136 ePaper.Sleep(); 137 138 if (--limit <= 0) while(1) yield(); // Wait here 139 140 delay(20000); // Wait here for 20s 141 142 // Wake up ePaper display so we can talk to it 143 Serial.println("Waking up!"); 144 ePaper.Init(INIT_LUT); 145 146 } // end of loop() 147 148 149 //------------------------------------------------------------------------------------ 150 // setRotation() actually rotates the drawing coordinates, not the whole display frame 151 // buffer so we can use this to draw text at right angles or upside down 152 //------------------------------------------------------------------------------------ 153 void rotateTest(void) 154 { 155 //frame.fillSprite(PAPER); // Fill buffer with white to clear old graphics 156 157 // Draw some text in frame buffer 158 frame.setTextFont(4); // Select font 4 159 frame.setTextColor(INK); // Set colour to ink 160 frame.setTextDatum(TC_DATUM); // Middle centre text datum 161 162 frame.setRotation(0); // Set the display rotation to 0, 1, 2 or 3 ( 1 & 3 = landscape) 163 epd_width = frame.width(); // Get the values for the current rotation 164 epd_height = frame.height(); // epd_height is not used in this sketch 165 166 frame.drawString("Rotation 0", epd_width / 2, 10); 167 168 frame.setRotation(1); // Set the display rotation to 1 169 epd_width = frame.width(); // Get the values for the current rotation 170 epd_height = frame.height(); // epd_height is not used in this sketch 171 172 frame.drawString("Rotation 1", epd_width / 2, 10); 173 174 frame.setRotation(2); // Set the display rotation to 2 175 epd_width = frame.width(); // Get the values for the current rotation 176 epd_height = frame.height(); // epd_height is not used in this sketch 177 178 frame.drawString("Rotation 2", epd_width / 2, 10); 179 180 frame.setRotation(3); // Set the display rotation to 3 181 epd_width = frame.width(); // Get the values for the current rotation 182 epd_height = frame.height(); // epd_height is not used in this sketch 183 184 frame.drawString("Rotation 3", epd_width / 2, 10); 185 186 Serial.println("Updating display"); 187 updateDisplay(); // Update display 188 }