Skip to content

Instantly share code, notes, and snippets.

@jfredett
Created February 3, 2018 17:18
Show Gist options
  • Save jfredett/0147ee42283b8487ac67b8827e0e35ff to your computer and use it in GitHub Desktop.
Save jfredett/0147ee42283b8487ac67b8827e0e35ff to your computer and use it in GitHub Desktop.
Pulsing Pseudocode
Assume the mic feeds something like a .wav at some sample rate.
So every cycle we get an array of voltages the mic saw at whatever
sample rate. Then calculate:
```
sample = <array of voltages>
max_v = maximum_of(sample)
min_v = minimum_of(sample)
pulse_coef = 0
for amt in sample:
pulse_coef += (amt - min_v) / max_v # this normalizes the amt to a value between 0 and 1
pulse_coef = pulse_coef / sample.length()
```
Now multiply the brightness of the LED (if you only control color,
this probably means just multiplying all the color valuesby the coef).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment