Benutzer-Werkzeuge

Webseiten-Werkzeuge


arduino:spektrumanalysator:programmversion_0.2

Spektrumanalysator - Programmversion 0.2

Dieser Programmversion liest einen Drehencoder aus.

https://www.pjrc.com/teensy/td_libs_Encoder.html

//Bibliotheken
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>
#include <Encoder.h>

//Encoderpins
#define encoderChannelA  24                   // Kanal A
#define encoderChannelB  25                   // Kanal B

Encoder myEnc(encoderChannelA, encoderChannelB);

long newPosition = 0;
long oldPosition;

// GUItool: begin automatically generated code
AudioInputAnalog         adc1;           //xy=144,93
AudioAnalyzePeak         peak1;          //xy=342,98
AudioAnalyzeFFT1024      fft1024_1;      //xy=348,149
AudioConnection          patchCord1(adc1, peak1);
AudioConnection          patchCord2(adc1, fft1024_1);
// GUItool: end automatically generated code
 
void setup() {
  Serial.begin(115200);  
    
  AudioMemory(10);
  // Configure the window algorithm to use
  fft1024_1.windowFunction(AudioWindowHanning1024);
  //myFFT.windowFunction(NULL);
}

void loop() {
  // Encoder
  newPosition = myEnc.read();
  if (newPosition != oldPosition) {
    oldPosition = newPosition;
    //Serial.println(newPosition);
  }
  
  // FFT
  float n;
  int i;

  if (fft1024_1.available()) {
    // each time new FFT data is available
    // print it all to the Arduino Serial Monitor
    Serial.print("FFT: ");
    for (i=0; i<40; i++) {
      n = fft1024_1.read(i);
      if (n >= 0.01) {
        Serial.print(n);
        Serial.print(" ");
      } else {
        Serial.print("  -  "); // don't print "0.00"
      }
    }
    
 
    if (peak1.available()) {
      int monoPeak = peak1.read() * 30.0;
      Serial.print(" peak:");
      Serial.print(monoPeak);
    }    
    
    // Serieller Output
    //Serial.print(" cpu:");
    //Serial.print(AudioProcessorUsageMax());
    //Serial.print(" mem:");
    //Serial.print(AudioMemoryUsageMax());
    Serial.print(" pos:");
    Serial.print(newPosition);
    Serial.println();
  }  
}
arduino/spektrumanalysator/programmversion_0.2.txt · Zuletzt geändert: 18.12.2022 15:26 von Frickelpiet