Created
October 23, 2016 17:58
-
-
Save tgk/cdcc5e3d05e08c52dfc2920a95811317 to your computer and use it in GitHub Desktop.
Fart machine for Rosalina - source
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
void fart(int pitch) { | |
int duration = random(300, 1000); | |
tone(8, pitch, duration); | |
delay(duration); | |
noTone(8); | |
} | |
int fartPitch() { | |
return map(analogRead(2), 0, 1023, 60, 110); | |
} | |
void setup() { | |
pinMode(4, INPUT); | |
pinMode(13, OUTPUT); | |
} | |
int buttonState = 0; | |
void loop() { | |
buttonState = digitalRead(4); | |
if(buttonState == HIGH) { | |
fart(fartPitch()); | |
digitalWrite(13, HIGH); | |
} else { | |
digitalWrite(13, LOW); | |
} | |
delay(50); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment