Next, we need to declare variables that we may want to change at a later time.
- blowThresshold will be the value of how loud the sound needed to trigger the current pitch.
- debounceTime is how long the debounce time should be to prevent multiple button triggers in one press. Set to 0.2 seconds.
- pitchLength, how many seconds we want the note to sound when triggered. Set to 1 second.
- pixelBrightness sets how bright the neopixels are. Can be between 0 and 1.
- SAMPLERATE is the number of samples of audio captured per seconds in Hertz. Set to 8000 Hz.
- NUM_SAMPLES is how many samples we're collecting. We want this to be tiny because the program will be running in a loop when we collect the samples continuously later. We just need to collect a little snippet of audio every time the program loop runs. (More on this later) If our sample rate is 8000 samples per second and we're collecting a 160 samples each time that gives us just 0.02 seconds of audio captured each time (160samples/8000samples/sec).
- The last string of variables are to set up notes to frequency values which are in Hertz. Find frequency values here.
# Magnitude of sound needed to trigger current pitch blowThresshold = 5000 # Time needed to debounce button, in seconds debounceTime = 0.2 # How long the note sounds for, in seconds pitchLength = 1 #neopixel brightness (Between 0 and 1) pixelBrightness = 0.05 #sample rate SAMPLERATE = 8000 # how many samples we're collecting NUM_SAMPLES = 160 #frequency values Ab3 = 208 A3 = 223 As3 = 233 Bb3 = 233 B3 = 247 C4 = 262 Cs4 = 277 Db4 = 277 D4 = 294 Ds4 = 311 Eb4 = 311 E4 = 330 F4 = 349 Fs4 = 370 Gb4 = 370 G4 = 392 Gs4 = 415
Text editor powered by tinymce.