M5Paper: canvas をタッチで切り替えて描画

こちらのプログラムを改造して、スクリーンタッチで画面が切り替わるようにしました。
[M5Paper: canvas をタイマーで切り替えて描画](https://qiita.com/ekzemplaro/items/bcdddcbfea439a28fb9c)

プログラム

```text:canvas_switch.ino
// ---------------------------------------------------------------
//	canvas_switch.ino
//
//						Jun/19/2022
// ---------------------------------------------------------------
#include <M5EPD.h>

M5EPD_Canvas canvas_a(&M5.EPD);
M5EPD_Canvas canvas_b(&M5.EPD);
M5EPD_Canvas canvas_c(&M5.EPD);
M5EPD_Canvas canvas_d(&M5.EPD);

int  point[2]; 
int  ncount = 0;
// ---------------------------------------------------------------
// [2-2]:
void prepare_canvas_a_proc()
{
	canvas_a.createCanvas(540, 960);
	canvas_a.setTextSize(5);
	canvas_a.drawString("canvas A",200,100);

	canvas_a.fillCenterSquare(100, 100, 50, WHITE);
	canvas_a.fillCenterSquare(200, 100, 40, WHITE);
	canvas_a.fillCenterSquare(300, 100, 30, WHITE);

	canvas_a.drawRoundRect(300, 300, 50, 30, 10, WHITE);

	canvas_a.fillCircle(200, 400, 30, WHITE);
	canvas_a.drawCircle(200, 500, 30, WHITE);

	canvas_a.fillCircle(300, 400, 15, WHITE);
	canvas_a.drawCircle(300, 500, 15, WHITE);

	canvas_a.fillEllipse(200, 600, 30,15, WHITE);
	canvas_a.drawEllipse(200, 700, 30, 15, WHITE);
	
	canvas_a.fillTriangle(200, 800, 300,800, 250,750, WHITE);
	canvas_a.drawTriangle(200, 900, 300,900, 250,850, WHITE);
	
	canvas_a.fillTriangle(400, 800, 500,800, 450,775, WHITE);
	canvas_a.drawTriangle(400, 900, 500,900, 450,875, WHITE);
}

// ---------------------------------------------------------------
// [2-4]:
void prepare_canvas_b_proc()
{
	canvas_b.createCanvas(540, 960);
	canvas_b.setTextSize(5);
	canvas_b.drawString("canvas B",200,150);

	canvas_b.fillCircle(100, 300, 50, WHITE);
	canvas_b.fillCircle(250, 300, 40, WHITE);
	canvas_b.fillCircle(400, 300, 30, WHITE);

}

// ---------------------------------------------------------------
// [2-6]:
void prepare_canvas_c_proc()
{
	canvas_c.createCanvas(540, 960);
	canvas_c.setTextSize(5);
	canvas_c.drawString("canvas C",200,200);

  
	canvas_c.fillTriangle(100, 800, 300,800, 200,700, WHITE);
	canvas_c.drawTriangle(100, 900, 300,900, 200,800, WHITE);
  
	canvas_c.fillTriangle(300, 800, 500,800, 400,700, WHITE);
	canvas_c.drawTriangle(300, 900, 500,900, 400,800, WHITE);
}

// ---------------------------------------------------------------
// [2-8]:
void prepare_canvas_d_proc()
{
	canvas_d.createCanvas(540, 960);
	canvas_d.setTextSize(5);
	canvas_d.drawString("canvas D",200,250);

  
	canvas_d.fillTriangle(100, 600, 300,600, 200,700, WHITE);
	canvas_d.drawTriangle(100, 700, 300,700, 200,800, WHITE);
  
	canvas_d.fillTriangle(300, 600, 500,600, 400,700, WHITE);
	canvas_d.drawTriangle(300, 700, 500,700, 400,800, WHITE);
}

// ---------------------------------------------------------------
// [2]:
void setup()
{
	M5.begin();
	M5.EPD.SetRotation(90);
	M5.TP.SetRotation(90);
	M5.EPD.Clear(true);

	prepare_canvas_a_proc();
	prepare_canvas_b_proc();
	prepare_canvas_c_proc();
	prepare_canvas_d_proc();

	canvas_a.pushCanvas(0,0,UPDATE_MODE_GLD16);
}

// ---------------------------------------------------------------
// [6]:
void loop()
{
	if(M5.TP.avaliable())
		{
		if(!M5.TP.isFingerUp())
			{
			if (finger_get_proc())
				{
				Serial.print("*** touched ***\r\n");
				canvas_switch_proc();
				}
			}
		}
}

// ---------------------------------------------------------------
// [6-4]:
bool finger_get_proc()
{
	bool is_update = false;
	M5.TP.update();
	tp_finger_t FingerItem = M5.TP.readFinger(0);
	if ((point[0] != FingerItem.x) || (point[1] != FingerItem.y))
		{
		is_update = true;
		Serial.printf("ncount = %d\r\n",ncount);
		point[0] = FingerItem.x;
		point[1] = FingerItem.y;
		Serial.printf("Finger ID:%d-->X: %d 	Y: %d	Size: %d\r\n", FingerItem.id, FingerItem.x, FingerItem.y , FingerItem.size);
		}

	return is_update;
}

// ---------------------------------------------------------------
// [6-8]:
void canvas_switch_proc()
{
	ncount++;
	short ikey = ncount % 4;
	switch (ikey)
		{
		case 0:
			canvas_a.pushCanvas(0,0,UPDATE_MODE_GLD16);
			break;
		case 1:
			canvas_b.pushCanvas(0,0,UPDATE_MODE_GLD16);
			break;
		case 2:
			canvas_c.pushCanvas(0,0,UPDATE_MODE_GLD16);
			break;
		case 3:
			canvas_d.pushCanvas(0,0,UPDATE_MODE_GLD16);
			break;
		}
}

// ---------------------------------------------------------------
```

Arduino IDE
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/179446/44d074b8-6d7b-ee65-d8f7-6a938751723a.png)