byte btn_1 = 3;
bool data_btn1 = 0;
#define ditekan 0
bool hold_btn1 = 0;
int counter = 0;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(btn_1, INPUT);
Serial.println();
}
void loop() {
// program utama berulang-ulang
data_btn1 = digitalRead(btn_1);//baca GPIO34
if (data_btn1 == ditekan) {
if (hold_btn1 == 0) {
counter += 1; // ini counter
Serial.print("counter: ");
Serial.println(counter);
hold_btn1 = 1;
}
} else {
hold_btn1 = 0;
}
}