#define pinTbl 2
#define pinBzr 3
void setup() {
// put your setup code here, to run once:
pinMode(pinTbl, INPUT);
pinMode(pinBzr, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
int tombolDitekan = digitalRead(pinTbl);
if (tombolDitekan==HIGH) {
playTone(1500);
}
delay(20);
}
void playTone(int frekuensi) {
long jeda = 1000000 / frekuensi / 2;
for (int i=0; i<100; i++) {
digitalWrite(pinBzr, HIGH);
delayMicroseconds(jeda);
digitalWrite(pinBzr, LOW);
delayMicroseconds(jeda);
}
}