2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

M5Paper: タッチパネルの使い方

2
Last updated at Posted at 2022-06-09
touch_counter.ino
// ---------------------------------------------------------------
//	touch_counter.ino
//
//						Jun/09/2022
// ---------------------------------------------------------------
#include <M5EPD.h>

M5EPD_Canvas canvas(&M5.EPD);

int	value = 0;
int	ncount = 0;
int	point[2]; 
// ---------------------------------------------------------------
void setup() {
  // put your setup code here, to run once:
	M5.begin();
	M5.EPD.SetRotation(90);
	M5.TP.SetRotation(90);
	M5.EPD.Clear(true);
	canvas.createCanvas(540, 960);
	canvas.setTextSize(5);


	canvas.fillTriangle(200, 300, 300,300, 250,200, WHITE);
	canvas.drawRect(200, 200, 100, 100, WHITE);
	
	canvas.fillTriangle(200, 500, 300,500, 250,600, WHITE);
	canvas.drawRect(200, 500, 100, 100, WHITE);
	
	canvas.drawString(String(value),200,400);

	canvas.drawString("ncount = " + String(ncount),50,50);
	canvas.pushCanvas(0,0,UPDATE_MODE_DU4);

	Serial.printf("ncount = %d\r\n",ncount);
	Serial.println("*** setup *** end ***");
}

// ---------------------------------------------------------------
void loop() {
  // put your main code here, to run repeatedly:

	if(M5.TP.avaliable()){
		if(!M5.TP.isFingerUp()){
			if (finger_get_proc())
				{
				value_hantei_proc();
				canvas.drawString(String(value) + "  ",200,400);
 				canvas.pushCanvas(0,0,UPDATE_MODE_DU4);
				}
			}
		}
}

// ---------------------------------------------------------------
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;
		ncount++;
		Serial.printf("ncount = %d\r\n",ncount);
		canvas.drawString("ncount = " + String(ncount),50,50);
		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;
}

// ---------------------------------------------------------------
void value_hantei_proc()
{
	if ((200 <= point[0]) && (point[0] <= 300))
		{
		if (point[1] <= 300)
			{
			value++;
			}
		else if (500 <= point[1])
			{
			value--;
			}
		}
}

// ---------------------------------------------------------------

Arduino IDE
image.png

IMG_20220609_172300.jpg

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?