Close

Changes

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/13/2015 at 19:590 Comments

Current state:

I've switched out the mic for better gain, and now have a small Neopixel ring for display.

Updated sketch

#include <Adafruit_NeoPixel.h>
#include <avr/power.h>
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>

#define PIN 5

Adafruit_NeoPixel strip = Adafruit_NeoPixel(12, PIN, NEO_GRB + NEO_KHZ800);
AudioInputAnalog         adc1;
AudioAnalyzeFFT1024      myFFT;
AudioConnection          patchCord1(adc1, 0, myFFT, 0);

int dled = 13;

void setup() {
  pinMode(dled, OUTPUT);
  AudioMemory(12);
  
  // Configure the window algorithm to use
  myFFT.windowFunction(AudioWindowHanning1024);
  
  strip.begin();
  strip.show(); // Initialize all pixels to 'off'
}

void loop() {
  float n;
  int i;
  int p;

  if (myFFT.available()) {
    // each time new FFT data is available
    for (i=0; i<strip.numPixels(); i++) {
      n = myFFT.read(i+5);
      if (n > 0.05) {
        p = (n+i)*1000;
        digitalWrite(dled, HIGH);
        strip.setPixelColor(i, Wheel(p));
        strip.show();
      }
    }
    digitalWrite(dled, LOW);
    colorWipe(strip.Color(0, 0, 0), 1);
  }
}

// Fill the dots one after the other with a color
void colorWipe(uint32_t c, uint8_t wait) {
  for(uint16_t i=0; i<strip.numPixels(); i++) {
      strip.setPixelColor(i, c);
      strip.show();
      delay(wait);
  }
}

// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
  WheelPos = 255 - WheelPos;
  if(WheelPos < 85) {
   return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  } else if(WheelPos < 170) {
    WheelPos -= 85;
   return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  } else {
   WheelPos -= 170;
   return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
  }
}

Discussions