Skip to content

Instantly share code, notes, and snippets.

@tiagomehackit
Last active January 16, 2020 08:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tiagomehackit/cfcc3f0076129c538ed637349743cf76 to your computer and use it in GitHub Desktop.
Save tiagomehackit/cfcc3f0076129c538ed637349743cf76 to your computer and use it in GitHub Desktop.
#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