Close

First Arduino sketch

A project log for Teensy 3.1 for Bitcoin

Bought a Teensy with Bitcoins from the Hackaday General Store. This project is a log of what I've done with it.

richard-hogbenRichard Hogben 06/06/2015 at 03:360 Comments

Mic is on pin 16 and LEDs are on PWM 23 and 22. The Teensy LED lights up for general frequency detection and the two LEDs light up and fade out at two higher frequencies.

#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>

AudioInputAnalog         adc1;
AudioAnalyzeFFT1024      myFFT;
AudioConnection          patchCord1(adc1, 0, myFFT, 0);

int aledg = 23;
int aledr = 22;
int dled = 13;
int brightness1 = 0;
int brightness2 = 0;

void setup() {
  pinMode(aledg, OUTPUT);
  pinMode(aledr, OUTPUT);
  pinMode(dled, OUTPUT);
  AudioMemory(12);
  
  // Configure the window algorithm to use
  myFFT.windowFunction(AudioWindowHanning1024);
}

void loop() {
  float n;
  int i;

  if (myFFT.available()) {
    // each time new FFT data is available
    for (i=4; i<175; i++) {
      n = myFFT.read(i);
      if (n >= 0.10) {
        digitalWrite(dled, HIGH);
      }
    }
    if ( myFFT.read(16) >= 0.10 ) {
      brightness1 = 255;
    }
    if ( myFFT.read(13) >= 0.10 ) {
      brightness2 = 255;
    }
    analogWrite(aledg, brightness1);
    analogWrite(aledr, brightness2);
    brightness1 = brightness1 -5;
    brightness2 = brightness2 -5;
    digitalWrite(dled, LOW);
  }
}

Discussions