Last active
January 16, 2020 08:07
-
-
Save tiagomehackit/cfcc3f0076129c538ed637349743cf76 to your computer and use it in GitHub Desktop.
reference code by Erik Kringen @ http://www.mycontraption.com/sound-effects-with-and-arduino/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "notes.h" // adds the notes.h | |
int speakerPin = 9;// pins defined as variables | |
int tiltPin = 2;// cause they are used many times in the program | |
void setup() { | |
pinMode(speakerPin, OUTPUT);// pin 9 piezo speaker - output | |
pinMode(tiltPin, INPUT_PULLUP);// pin 2 tilt switch - input | |
Serial.begin(9600);// debugging helps! | |
} | |
void loop() { | |
int soundNumber = random(4);// random value 0-3 saves to "soundNumber" | |
if (digitalRead(tiltPin) == LOW) { | |
// turns "soundNumber" to 4 | |
} | |
// print "soundNumber" to serial monitor | |
// add a delay of 1-2 seconds | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment