فهرست منبع

add 2.13 part for arduino

hnwangkg-ezio 5 سال پیش
والد
کامیت
e25d0bc44a
3فایلهای تغییر یافته به همراه47 افزوده شده و 22 حذف شده
  1. 25 5
      Arduino UNO/epd2in13_V2/epd2in13_V2.cpp
  2. 1 0
      Arduino UNO/epd2in13_V2/epd2in13_V2.h
  3. 21 17
      Arduino UNO/epd2in13_V2/epd2in13_V2.ino

+ 25 - 5
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.

+ 1 - 0
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:

+ 21 - 17
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;
-    }
-
-    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();
+  // put your setup code here, to run once:
+  Serial.begin(9600);
+  Serial.println("epd FULL");
+  epd.Init(FULL);
+  epd.Display(IMAGE_DATA);
+
+  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()
 {
 
 }
-