diff --git a/Arduino UNO/epd2in13_V2/epd2in13_V2.cpp b/Arduino UNO/epd2in13_V2/epd2in13_V2.cpp index f1ec30a..7250e49 100644 --- a/Arduino UNO/epd2in13_V2/epd2in13_V2.cpp +++ b/Arduino UNO/epd2in13_V2/epd2in13_V2.cpp @@ -103,10 +103,11 @@ void Epd::SendData(unsigned char data) */ void Epd::WaitUntilIdle(void) { - while(DigitalRead(busy_pin) == 1) { //LOW: idle, HIGH: busy + while(1) { //LOW: idle, HIGH: busy + if(DigitalRead(busy_pin) == 0) + break; DelayMs(100); } - DelayMs(200); } int Epd::Init(char Mode) @@ -276,14 +277,14 @@ void Epd::DisplayPartBaseImage(const unsigned char* frame_buffer) SendCommand(0x24); for (int j = 0; j < h; j++) { for (int i = 0; i < w; i++) { - SendData(frame_buffer[i + j * w]); + SendData(pgm_read_byte(&frame_buffer[i + j * w])); } } SendCommand(0x26); for (int j = 0; j < h; j++) { for (int i = 0; i < w; i++) { - SendData(frame_buffer[i + j * w]); + SendData(pgm_read_byte(&frame_buffer[i + j * w])); } } } @@ -304,7 +305,7 @@ void Epd::DisplayPart(const unsigned char* frame_buffer) SendCommand(0x24); for (int j = 0; j < h; j++) { for (int i = 0; i < w; i++) { - SendData(frame_buffer[i + j * w]); + SendData(pgm_read_byte(&frame_buffer[i + j * w])); } } } @@ -316,6 +317,25 @@ void Epd::DisplayPart(const unsigned char* frame_buffer) WaitUntilIdle(); } +void Epd::ClearPart(void) +{ + int w, h; + w = (EPD_WIDTH % 8 == 0)? (EPD_WIDTH / 8 ): (EPD_WIDTH / 8 + 1); + h = EPD_HEIGHT; + SendCommand(0x24); + for (int j = 0; j < h; j++) { + for (int i = 0; i < w; i++) { + SendData(0xff); + } + } + + //DISPLAY REFRESH + SendCommand(0x22); + SendData(0x0C); + SendCommand(0x20); + WaitUntilIdle(); +} + /** * @brief: After this command is transmitted, the chip would enter the * deep-sleep mode to save power. diff --git a/Arduino UNO/epd2in13_V2/epd2in13_V2.h b/Arduino UNO/epd2in13_V2/epd2in13_V2.h index 70e331d..3db5adc 100644 --- a/Arduino UNO/epd2in13_V2/epd2in13_V2.h +++ b/Arduino UNO/epd2in13_V2/epd2in13_V2.h @@ -56,6 +56,7 @@ public: void Display(const unsigned char* frame_buffer); void DisplayPartBaseImage(const unsigned char* frame_buffer); void DisplayPart(const unsigned char* frame_buffer); + void ClearPart(void); void Sleep(void); private: diff --git a/Arduino UNO/epd2in13_V2/epd2in13_V2.ino b/Arduino UNO/epd2in13_V2/epd2in13_V2.ino index 11cd6f2..915a27d 100644 --- a/Arduino UNO/epd2in13_V2/epd2in13_V2.ino +++ b/Arduino UNO/epd2in13_V2/epd2in13_V2.ino @@ -6,22 +6,27 @@ Epd epd; void setup() { - // put your setup code here, to run once: - Serial.begin(9600); - if (epd.Init(FULL) != 0) { - Serial.println("e-Paper init failed"); - return; - } + // put your setup code here, to run once: + Serial.begin(9600); + Serial.println("epd FULL"); + epd.Init(FULL); + epd.Display(IMAGE_DATA); - Serial.println("e-Paper clear"); - epd.Clear(); - - Serial.println("e-Paper show pic"); - epd.Display(IMAGE_DATA); - - Serial.println("e-Paper clear and sleep"); - epd.Clear(); - epd.Sleep(); + Serial.println("epd PART"); + epd.DisplayPartBaseImage(IMAGE_DATA); + char i = 0; + for (i = 0; i < 10; i++) { + Serial.println("e-Paper PART IMAGE_DATA"); + epd.Init(PART); + epd.DisplayPart(IMAGE_DATA); + Serial.println("e-Paper PART Clear"); + epd.ClearPart(); + } + + epd.Init(FULL); + Serial.println("e-Paper clear and sleep"); + epd.Clear(); + epd.Sleep(); } @@ -29,4 +34,3 @@ void loop() { } -