プログラム
touch_panel01.ino
// ---------------------------------------------------------------
// touch_panel01.ino
//
// Feb/24/2025
// ---------------------------------------------------------------
#include <M5Core2.h>
#define RADIUS 50
#define HANTEI 60
bool button_a = false;
bool button_b = false;
int pos_before[] = {0,0};
int count_omit = 0;
int nn = 0;
// ---------------------------------------------------------------
void setup() {
M5.begin();
M5.Lcd.fillScreen(TFT_BLACK);
M5.Lcd.fillCircle(60, 120, RADIUS, GREEN);
M5.Lcd.fillCircle(260, 120, RADIUS, GREEN);
}
// ---------------------------------------------------------------
void touch_proc(int xx_in, int yy_in)
{
int ip = sq(xx_in - 60) + sq(yy_in - 120);
double lla = sqrt(ip);
int iq = sq(xx_in - 260) + sq(yy_in - 120);
double llb = sqrt(iq);
Serial.printf("nn = %d\t",nn);
Serial.printf("lla = %f\t",lla);
Serial.printf("llb = %f\n",llb);
if (lla <= HANTEI)
{
if(button_a)
{
M5.Lcd.fillCircle(60, 120, RADIUS, GREEN);
}
else
{
M5.Lcd.fillCircle(60, 120, RADIUS, RED);
}
button_a = !button_a;
}
else if (llb <= HANTEI)
{
if(button_b)
{
M5.Lcd.fillCircle(260, 120, RADIUS, GREEN);
}
else
{
M5.Lcd.fillCircle(260, 120, RADIUS, RED);
}
button_b = !button_b;
}
nn++;
}
// ---------------------------------------------------------------
void loop() {
M5.update(); // タッチ状態を更新
if (M5.Touch.ispressed()) {
Point touchPoint = M5.Touch.getPressPoint();
if ((pos_before[0]!= touchPoint.x) && (pos_before[1] != touchPoint.y)
&& (70 <=touchPoint.y) && (touchPoint.y <= 170))
{
touch_proc(touchPoint.x, touchPoint.y);
pos_before[0] = touchPoint.x;
pos_before[1] = touchPoint.y;
count_omit = 10;
}
}
delay(100); // ループの遅延
if (0 < count_omit)
{
count_omit--;
}
else
{
pos_before[0] = 0;
pos_before[1] = 0;
}
}
// ---------------------------------------------------------------