quwrof
M5Stack basic, bela trill craft, e-textile, ArduinolDE I wanted to use these to create a conductive cloth touch sensor that would respond to touch at three different locations and play a different sound each time, so I wrote the following program in C++.
However, because the conductive fabric is too large, it becomes like a proximity sensor as well as a touch sensor, making it impossible to determine the location of the three touches. When this kind of problem occurs with capacitive touch sensors, it is usual to change the threshold value, but since the touch values are extremely discriminated, adjusting the threshold value cannot solve the problem. And now I wanted to adjust the prescaler, but I don't know how to do it. Can anyone please advise me how to do this?
void loop() {
giBattery = M5.Power.getBatteryLevel();
M5.Lcd.setCursor(0, 0);
M5.Lcd.printf("%3d \%",giBattery);
M5.Lcd.printf("%%");
// Trill Craftからデータを要求
Wire.beginTransmission(TRILL_I2C_ADDRESS);
Wire.write(0x04); // ペイロードを読むコマンド
Wire.endTransmission();
Wire.requestFrom(TRILL_I2C_ADDRESS, 60); // データを要求
if (Wire.available() >= 4) { // 必要なデータの長さが4バイト以上であることを確認
uint8_t buffer[4];
Wire.readBytes(buffer, 4); // 最初の4バイトを読み取る
int touchPosition = buffer[0]; // 最初のバイトをタッチ位置として読み取る
int touchValue = buffer[1]; // 2番目のバイトをタッチ値として読み取る
Serial.print("Touch Position: ");
Serial.print(touchPosition);
Serial.print(", Touch Value: ");
Serial.println(touchValue); // センサー値をシリアルプロッタに表示
if (touchPosition != currentTouchPosition) {
currentTouchPosition = touchPosition;
// タッチ位置をM5Stackに表示
M5.Lcd.fillScreen(BLACK);
//M5.Lcd.setTextColor();
M5.Lcd.setCursor(0, 80);
M5.Lcd.printf("Position: %d\n", currentTouchPosition);
M5.Lcd.printf("Value: %d\n", touchValue);
byte data;
Serial.printf("Touch Position: %d\n", currentTouchPosition);
// タッチ位置に基づいて異なるMP3ファイルを再生
if(touchValue > 127){
switch (currentTouchPosition) {
case 0:
Serial.println("Playing piano_c4_2.mp3");
playMP3("/piano_c4_2.mp3");
break;
case 3:
Serial.println("Playing piano_d4_2.mp3");
playMP3("/piano_d4_2.mp3");
break;
case 6:
Serial.println("Playing piano_e4_2.mp3");
playMP3("/piano_e4_2.mp3");
break;
default:
// タッチ位置が0, 3, 6以外の場合、再生を停止
Serial.println("Touch position not recognized. No action taken.");
break;
}
}
}
}
giBatteryOld = giBattery;
delay(100); // センサーへの過度な負荷を避けるための小さな遅延
}