diff --git a/examples/02.Digital/toneKeyboard/toneKeyboard.ino b/examples/02.Digital/toneKeyboard/toneKeyboard.ino index c8e73c6..64c1438 100644 --- a/examples/02.Digital/toneKeyboard/toneKeyboard.ino +++ b/examples/02.Digital/toneKeyboard/toneKeyboard.ino @@ -19,6 +19,8 @@ #include "pitches.h" +int buzzerPin = 8; + const int threshold = 10; // minimum reading of the sensors that generates a note // notes to play, corresponding to the 3 sensors: @@ -37,7 +39,7 @@ void loop() { // if the sensor is pressed hard enough: if (sensorReading > threshold) { // play the note corresponding to this sensor: - tone(8, notes[thisSensor], 20); + tone(buzzerPin, notes[thisSensor], 20); } } } diff --git a/examples/02.Digital/toneMelody/toneMelody.ino b/examples/02.Digital/toneMelody/toneMelody.ino index 22022dc..7afcb69 100644 --- a/examples/02.Digital/toneMelody/toneMelody.ino +++ b/examples/02.Digital/toneMelody/toneMelody.ino @@ -17,6 +17,8 @@ #include "pitches.h" +int buzzerPin = 8; + // notes in the melody: int melody[] = { NOTE_C4, NOTE_G3, NOTE_G3, NOTE_A3, NOTE_G3, 0, NOTE_B3, NOTE_C4 @@ -34,14 +36,14 @@ void setup() { // to calculate the note duration, take one second divided by the note type. //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc. int noteDuration = 1000 / noteDurations[thisNote]; - tone(8, melody[thisNote], noteDuration); + tone(buzzerPin, melody[thisNote], noteDuration); // to distinguish the notes, set a minimum time between them. // the note's duration + 30% seems to work well: int pauseBetweenNotes = noteDuration * 1.30; delay(pauseBetweenNotes); // stop the tone playing: - noTone(8); + noTone(buzzerPin); } } diff --git a/examples/02.Digital/toneMultiple/toneMultiple.ino b/examples/02.Digital/toneMultiple/toneMultiple.ino index 8d97fa7..ec3003b 100644 --- a/examples/02.Digital/toneMultiple/toneMultiple.ino +++ b/examples/02.Digital/toneMultiple/toneMultiple.ino @@ -15,25 +15,29 @@ https://www.arduino.cc/en/Tutorial/BuiltInExamples/toneMultiple */ +int buzzerOnePin = 6; +int buzzerTwoPin = 7; +int buzzerThreePin = 8; + void setup() { } void loop() { // turn off tone function for pin 8: - noTone(8); + noTone(buzzerThreePin); // play a note on pin 6 for 200 ms: - tone(6, 440, 200); + tone(buzzerOnePin, 440, 200); delay(200); // turn off tone function for pin 6: - noTone(6); + noTone(buzzerOnePin); // play a note on pin 7 for 500 ms: - tone(7, 494, 500); + tone(buzzerTwoPin, 494, 500); delay(500); // turn off tone function for pin 7: - noTone(7); + noTone(buzzerTwoPin); // play a note on pin 8 for 300 ms: - tone(8, 523, 300); + tone(buzzerThreePin, 523, 300); delay(300); } diff --git a/examples/02.Digital/tonePitchFollower/tonePitchFollower.ino b/examples/02.Digital/tonePitchFollower/tonePitchFollower.ino index 592f671..ca0422f 100644 --- a/examples/02.Digital/tonePitchFollower/tonePitchFollower.ino +++ b/examples/02.Digital/tonePitchFollower/tonePitchFollower.ino @@ -17,6 +17,8 @@ https://www.arduino.cc/en/Tutorial/BuiltInExamples/tonePitchFollower */ +int buzzerPin = 9; + void setup() { // initialize serial communications (for debugging only): Serial.begin(9600); @@ -34,6 +36,6 @@ void loop() { int thisPitch = map(sensorReading, 400, 1000, 120, 1500); // play the pitch: - tone(9, thisPitch, 10); + tone(buzzerPin, thisPitch, 10); delay(1); // delay in between reads for stability } pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy