

#include <SPI.h>
#include <epd1in54.h>
#include <epdpaint.h>
#include "imagedata.h"

#define COLORED     0
#define UNCOLORED   1

unsigned char image[1024];
Paint paint(image, 0, 0); 
Epd epd;
unsigned long time=0;


void setup()
{
  /*put your setup code here, to run once:*/
  Serial.begin(9600);
  if (epd.Init(lut_full_update) != 0) 
  {
      Serial.print("e-Paper init failed");
      return;
  }
  /** 
   *  there are 2 memory areas embedded in the e-paper display
   *  and once the display is refreshed, the memory area will be auto-toggled,
   *  i.e. the next action of SetFrameMemory will set the other memory area
   *  therefore you have to clear the frame memory twice.
   */
  epd.ClearFrameMemory(0xFF); 
  epd.DisplayFrame();
  epd.ClearFrameMemory(0xFF);  
  epd.DisplayFrame();
  delay(1000);

  if (epd.Init(lut_partial_update) != 0)
  {
      Serial.print("e-Paper init failed");
      return;
  }
  /*Use to display pictures*/
  epd.SetFrameMemory(IMAGE_DATA);
  epd.DisplayFrame();
  epd.SetFrameMemory(IMAGE_DATA);
  epd.DisplayFrame();
  delay(2000);

  epd.SetFrameMemory(IMAGE_DATA1);
  epd.DisplayFrame();
  epd.SetFrameMemory(IMAGE_DATA1);
  epd.DisplayFrame();
  delay(2000);

  epd.SetFrameMemory(IMAGE_DATA2);
  epd.DisplayFrame();
  epd.SetFrameMemory(IMAGE_DATA2);
  epd.DisplayFrame();
  delay(1000);
  
  epd.SetFrameMemory(IMAGE_DATA2);
  epd.DisplayFrame();
  epd.SetFrameMemory(IMAGE_DATA2);
  epd.DisplayFrame();
  
}


void loop() {
  /* put your main code here, to run repeatedly*/
  time++;
  char time_string[] = {'0', '0', ':','0', '0', ':', '0', '0', '\0'};
  time_string[0] = time / 3600 / 10 + '0';
  time_string[1] = time / 3600 % 10 + '0';
  time_string[3] = time / 60 / 10 + '0';
  time_string[4] = time / 60 % 10 + '0';
  time_string[6] = time % 60 / 10 + '0';
  time_string[7] = time % 60 % 10 + '0';

  paint.SetWidth(28);
  paint.SetHeight(100);
  paint.SetRotate(ROTATE_270);

  paint.Clear(UNCOLORED);
  paint.DrawStringAt(0, 4, time_string, &Font16, COLORED);
  epd.SetFrameMemory(paint.GetImage(), 48 ,45 , paint.GetWidth(), paint.GetHeight());
  epd.DisplayFrame();
  
  delay(1000);

}

