From 0d59a378c3edccbaa20518280bbb6e18c8e47128 Mon Sep 17 00:00:00 2001 From: nicolas-f <1382241+nicolas-f@users.noreply.github.com> Date: Tue, 20 Feb 2024 16:27:42 +0100 Subject: [PATCH] Create buzzer_test.js --- buzzer_test.js | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 buzzer_test.js diff --git a/buzzer_test.js b/buzzer_test.js new file mode 100644 index 0000000..0c5be57 --- /dev/null +++ b/buzzer_test.js @@ -0,0 +1,37 @@ +var PIN_BUZZER = D4; +var PIN_BUZZER2 = A0; +var PIN_BUZZER3 = D9; +var buzzerEnabled = false; +var buzzerEnabled2 = false; +var buzzerEnabled3 = false; + +function switchBuzzerState1() { + buzzerEnabled = !buzzerEnabled; + if(buzzerEnabled) { + digitalWrite(PIN_BUZZER,255); + } else { + digitalWrite(PIN_BUZZER,0); + } +} + +function switchBuzzerState2() { + buzzerEnabled2 = !buzzerEnabled2; + if(buzzerEnabled2) { + digitalWrite(PIN_BUZZER2,255); + } else { + digitalWrite(PIN_BUZZER2,0); + } +} + +function switchBuzzerState3() { + buzzerEnabled3 = !buzzerEnabled3; + if(buzzerEnabled3) { + analogWrite(PIN_BUZZER3, 0.5,{freq:4000}); + } else { + digitalWrite(PIN_BUZZER3, 0); + } +} + +setWatch(switchBuzzerState1, BTN3, { repeat: true, edge: 'rising'}); +setWatch(switchBuzzerState2, BTN2, { repeat: true, edge: 'rising'}); +setWatch(switchBuzzerState3, BTN1, { repeat: true, edge: 'rising'});