Skip to content

Instantly share code, notes, and snippets.

@pelcarlo
Last active December 26, 2020 21:22
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 pelcarlo/9f8216d239c03a3017176e80ecbcda7e to your computer and use it in GitHub Desktop.
Save pelcarlo/9f8216d239c03a3017176e80ecbcda7e to your computer and use it in GitHub Desktop.
teensy lowpass breath controller
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif
// GUItool: begin automatically generated code
AudioInputI2S i2s1; //xy=429,350
AudioFilterStateVariable filter1; //xy=677,374
AudioOutputI2S i2s2; //xy=988,390
AudioConnection patchCord1(i2s1, 0, filter1, 0);
AudioConnection patchCord2(filter1, 0, i2s2, 0);
AudioConnection patchCord3(filter1, 0, i2s2, 1);
AudioControlSGTL5000 sgtl5000_1; //xy=825,587
// GUItool: end automatically generated code
#define PIN 6
#define NUMPIXELS 12
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
void setup()
{
AudioMemory(256);
pixels.begin();
Serial.begin(115200);
sgtl5000_1.enable();
sgtl5000_1.volume(0.8);
delay(50);
}
unsigned long safeMap(int data, int min, int max, int out1, int out2)
{
if (data < min)
{
data = min;
}
if (data > max)
{
data = max;
}
return map(data, min, max, out1, out2);
}
void loop()
{
unsigned long resonanceKnob = analogRead(A3);
//filter is working
if (resonanceKnob > 20)
{
unsigned long pressure = analogRead(A1);
int min = 90;
int max = 700;
unsigned long fre = safeMap(pressure, min, max, 1000, 20000);
int res = map(resonanceKnob, 0, 1024, 1, 5);
filter1.frequency(fre);
filter1.resonance(res);
int led = map(fre, 0, 20000, 0, NUMPIXELS);
for (int i = 1; i < NUMPIXELS; i++)
{
if (i < led)
{
pixels.setPixelColor(i, pixels.Color(0, 255, 25));
}
else
{
pixels.setPixelColor(i, pixels.Color(0, 0, 0));
}
}
pixels.setPixelColor(0, pixels.Color(0, 25, 255));
pixels.show();
}
else
{
filter1.frequency(20000);
filter1.resonance(5);
for (int i = 1; i < NUMPIXELS; i++)
{
pixels.setPixelColor(i, pixels.Color(0, 0, 0));
}
pixels.setPixelColor(0, pixels.Color(255, 0, 0));
pixels.show();
delay(150);
pixels.setPixelColor(0, pixels.Color(0, 0, 0));
pixels.show();
delay(150);
}
delay(8);
}
@pelcarlo
Copy link
Author

Cattura

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment