Who can help me? I want to tap the piezo at A0 so that this code works only when

Who can help me? I want to tap the piezo at A0 so that this code works only when I tap the piezo.

const unsigned char data1[] PROGMEM =
{
0x80,0x7F,0x80,0x7F,0x7E,0x7F,0x7E,0x80,0x80,0x7E,0x7E,
0x7D,0x7E,0x7F,0x7D,0x7C,0x7F,0x7E,0x7B,0x7E,0x7E,0x7D,
0x7C,0x7B,0x7C,0x7F,0x7D,0x7D,0x7C,0x7B,0x7D,0x7D,0x7B,
0x7C,0x7F,0x7D,0x82,0x82,0x7D,0x80,0x7F,0x7F,0x81,0x7D,
0x81,0x80,0x7D,0x80,0x86,0x7E,0x7C,0x7F,0x80,0x81,0x80,
0x81,0x7F,0x80,0x7F,0x81,0x7E,0x81,0x80,0x7E,0x80,0x83,
0x7F,0x7E,0x7E,0x80,0x7F,0x82,0x81,0x7D,0x80,0x79,0x81,
0x34,0x01,0x09,0x00,0x08,0x04,0x08,0x01,0x05,0x07,0x03,0x7A,0x7B,0x7C,0x7B,0x7C,0x7D,0x7C,0x7D,0x7E,
};

void setup() {

DDRC = 255;
}

short i = 0;

void loop() {
PORTC = pgm_read_byte(&(data1[i++]));
if (i >= sizeof(data1))
i = 0;
delayMicroseconds(62);

}

What happens when you run your program and what do you want it to do that is different?

What is the purpose of the program?

Post a link to the datasheet for your piezo device.

...R

PORTC = pgm_read_byte(&(data1[i++]));you do know that the more normal way to write that is

PORTC = pgm_read_byte(data1 + i);
i++;

See this tutorial for using a piezo element as a knock sensor:
https://www.arduino.cc/en/tutorial/knock

What Arduino are you using? I hope it's an Arduino MEGA if you want to use A0 for input and PORTC for output.

I have to confess That I didn't write the code myself I watched his here Arduino audio sampling tutorial (part 1) - YouTube I use MEGA2560 I didn't write the code. But I am interested in making an electric drum by knocking a piezo and making a sound. Must apologize in English. I'm not good at it.

jaroontimtes:
Must apologize in English. I'm not good at it.

Your English seems very good.

Do you have a piezo sensor? If so, what one do you have?

...R

I have a piezo but I don't know how to write the code. How to make it sound From the code you see It's loud, doesn't stop.

jaroontimtes:
I have a piezo

But you still have not told us exactly what piezo you have. This is the 3rd time of asking.

Post a link to its datasheet.

...R

Sorry again I do not understand And i am trying Can you please explain "Post a link to its datasheet."

A datasheet is the document a manufacturer publishes which describes a component in detail. It should be available on the manufacturer's site, or if you're lucky there may be a link to it from the vendor.

Thanks for the explanation But I don't have the documents you mentioned Thank you again for trying to help me. Thank you.

jaroontimtes:
Thanks for the explanation But I don't have the documents you mentioned Thank you again for trying to help me. Thank you.

Where did you buy the piezo device?

If you bought it on the internet post a link to the webpage where you bought it.

Posting a photo of the device may help us to identify it. See this Simple Image Posting Guide

...R

I ordered https://www.lazada.co.th/products/12-27-piezos-i5874924-s7251595.htmlhttps://www.lazada.co.th/products/12-27-piezos-i5874924-s7251595.html
And I use the r2r circuit here. https://cdn.instructables.com/FGY/C0NC/H742FUAL/FGYC0NCH742FUAL.LARGE.jpg?auto=webp&frame=1&width=1024&height=1024&fit=bounds
The code is now working. And the sound of the speaker But it's loud no stop I want it to make a sound only when I tap the piezo.

I have to apologize again that my post looks sloppy. I still don't understand. At this time, the code is working. And the sound of the speaker But it's loud no stop I want it to make a sound only when I tap the piezo.

jaroontimtes:
I have to apologize again that my post looks sloppy. I still don't understand. At this time, the code is working. And the sound of the speaker But it's loud no stop I want it to make a sound only when I tap the piezo.

Did you follow the link in reply #3?

From your link I think those things are intended to be piezo buzzers (to make a noise) but maybe they also work in "reverse" so that tapping them generates an electric current.

This Arduino Knock tutorial may help

...R

PS ... just realized you were already given that link way back in Reply #3

I thank everyone who helped me solve the problem. And I am trying to study the response 3 # with determination If i succeed I will come back to thank you again.