Welcome, Guest
Username: Password: Remember me

TOPIC: Arduino FFT Spectrum Analyzer with pedalSHIELDMEGA

Arduino FFT Spectrum Analyzer with pedalSHIELDMEGA 9 months 3 weeks ago #1476

  • Ray
  • Ray's Avatar
  • OFFLINE
  • Moderator
  • Posts: 615
  • Thank you received: 138
  • Karma: 38
This is a poor man's spectrum analyzer with pedalSHIELD MEGA. it basically uses the ADC0 to read the analog signal and plot it on the 128x64 OLED display.



The code is a modification of the code by blurtime (blurtime.blogspot.com/2010/11/arduino-re...-audio-spectrum.html) all credit to him.
//Based on previous works by http://blurtime.blogspot.com/2010/11/arduino-realtime-audio-spectrum.html
//Adapted and Coded by RAy www.electrosmash.com
 
#include "U8glib.h"
#include "fix_fft.h"
U8GLIB_SH1106_128X64 u8g(U8G_I2C_OPT_NO_ACK);  // Display which does not send ACK
 
//defining hardware resources.
#define LED 13
#define FOOTSWITCH 12
#define TOGGLE 2
#define PUSHBUTTON_1 A5
#define PUSHBUTTON_2 A4

//other variables
int input, bit_crush_variable=0;
int counter=0;
int count=64; //initially in mid position
 
char im[128], data[128];
char x = 0, ylim = 64;
int i = 0, val;
int dat, var;
int min=1024, max=0;
 
void setup() {
  //setup IO
  pinMode(FOOTSWITCH, INPUT_PULLUP);
  pinMode(TOGGLE, INPUT_PULLUP); 
  pinMode(PUSHBUTTON_1, INPUT_PULLUP);
  pinMode(PUSHBUTTON_2, INPUT_PULLUP);
  pinMode(LED, OUTPUT);
  pinMode(6, OUTPUT); //PWM0 as output
  pinMode(7, OUTPUT); //PWM1 as output
 
  u8g.firstPage();
 do {
    u8g.setFont(u8g_font_helvR18r);
    u8g.drawStr( 0, 30, " Spectrum");
    u8g.drawStr( 0, 60, "  Analyzer");   
    } while( u8g.nextPage() );
delay (1500);
  }
 
void loop() 
{   
//turn on the LED when footswitch pressed
if (digitalRead(FOOTSWITCH)) digitalWrite(LED, HIGH); 
else digitalWrite(LED, LOW);
 
//read the audio signal
  for ( i = 0; i < 128; i++) 
  {
    val = analogRead(A0);
    data[i] = val / 4 - 128;
    im[i] = 0;
    if(val>max) max=val;
    if(val<min) min=val;
  }
 
  fix_fft(data, im, 7, 0);
 
if(digitalRead(TOGGLE))//if the toogle is HIGH make a fine FFT representation
{
 u8g.firstPage(); 
    do {
     for ( i = 1; i < 64; i++) 
     {   
      dat = sqrt(data[i] * data[i] + im[i] * im[i]);   
      var = ylim - dat;
      if (var<0) var=0;
      u8g.drawLine(i*2 + x, ylim, i*2 + x,var ); // skip displaying the 0-500hz band completely.
     }
        } while( u8g.nextPage() ); 
}
else //if the toogle is LOW make a course FFT representation
{
  u8g.firstPage(); 
    do {
     for ( i = 1; i < 64; i+=2) 
     {       
      dat= sqrt(data[i] * data[i] + im[i] * im[i]);  
      var = ylim - dat;
      if (var<0) var=0;
      u8g.drawLine(i*2 + x, ylim, i*2 + x,var );
      u8g.drawLine((i*2 + x)+1, ylim, (i*2 + x)+1,var );
     }
        } while( u8g.nextPage() ); 
}
}

The hardware configuration and the number of resources that the FFT takes make the Arduino unable to play back the signal at the same time that it is represented, so if you want to just visualize the signal is fine. BUT if you want the signal to be visualized and also to go (clean) through the pedal you would need to use a small cable to jump input and output pins like the image below:

IMG_0292.jpg
Last Edit: 9 months 3 weeks ago by Ray.
The administrator has disabled public write access.

Arduino FFT Spectrum Analyzer with pedalSHIELDMEGA 1 month 2 weeks ago #1747

  • synesthesia
  • synesthesia's Avatar
  • OFFLINE
  • New Member
  • Posts: 11
  • Thank you received: 5
  • Karma: 2
Nice looking bars =))) damn i deeply like to know how fast fourier transform works in Arduino.

Can i merge previous codes? I mean after all effects we scroll, get to the frequency domain utility and monitoring our signal? (Doesn't matter there's no sound on output)
Desperate electronics enginner | Passionate audio hobbyist.
The administrator has disabled public write access.
The following user(s) said Thank You: Ray

Arduino FFT Spectrum Analyzer with pedalSHIELDMEGA 1 month 2 weeks ago #1755

  • Ray
  • Ray's Avatar
  • OFFLINE
  • Moderator
  • Posts: 615
  • Thank you received: 138
  • Karma: 38
Yes sure, you can merge with any other codes. Thats a cool idea.
The administrator has disabled public write access.

Arduino FFT Spectrum Analyzer with pedalSHIELDMEGA 1 month 1 week ago #1758

  • synesthesia
  • synesthesia's Avatar
  • OFFLINE
  • New Member
  • Posts: 11
  • Thank you received: 5
  • Karma: 2
Sorry for my lack of english. I meant after all effects we scroll, finally get to the frequency domain utility and monitoring our signal. And doesn't matter there's no sound on output this time.

I think it requires a lot of work, first pasting variables in correct place, then place another condition after increasing/decreasing switches to get to this mode. then disconnecting output in case of what you've said above, i'm looking silly now :S
// www.Electrosmash.com/pedalshield-mega
 
#include "U8glib.h"
U8GLIB_SH1106_128X64 u8g(U8G_I2C_OPT_NO_ACK);  // Display which does not send ACK
 
//defining hardware resources.
#define LED 13
#define FOOTSWITCH 12
#define TOGGLE 2
#define PUSHBUTTON_1 A5
#define PUSHBUTTON_2 A4

//defining the output PWM parameters
#define PWM_FREQ 0x00FF // pwm frequency - 31.3KHz
#define PWM_MODE 0 // Fast (1) or Phase Correct (0)
#define PWM_QTY 2 // 2 PWMs in parallel

//other variables
int input, distortion_threshold=16000; //initial value adjusted by try and error.
int count, counter=0;
unsigned int ADC_low, ADC_high;
 
const uint8_t sleeping_cat128x64[] U8G_PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x9C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x1C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x1E, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x3C, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x01, 0xFC, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x0F, 0xFF, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x1F, 0xFF, 0xC0, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0x8E, 0x00, 0x00, 0x00, 0x00, 0x7F, 0xFF, 0xE0, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x0F, 0xC1, 0x8E, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xF0, 0x00, 0x00,
0x00, 0x00, 0x00, 0x03, 0xFF, 0x87, 0x8E, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xF8, 0x00, 0x00,
0x00, 0x00, 0x00, 0x1F, 0xFF, 0x07, 0x8E, 0x00, 0x00, 0x00, 0x01, 0xFF, 0xFF, 0xFC, 0x00, 0x00,
0x00, 0x00, 0x00, 0x7F, 0xF0, 0x00, 0x86, 0x00, 0x00, 0x00, 0x03, 0xFE, 0xFF, 0xFC, 0x00, 0x00,
0x00, 0x00, 0x01, 0xFB, 0xF8, 0x00, 0x06, 0x00, 0x00, 0x00, 0x03, 0xFC, 0x3F, 0xFE, 0x00, 0x00,
0x00, 0x00, 0x07, 0xF1, 0xFC, 0x00, 0x07, 0x00, 0x00, 0x00, 0x03, 0xFE, 0x07, 0xFE, 0x00, 0x00,
0x00, 0x00, 0x1F, 0xF8, 0xFC, 0x00, 0x07, 0x80, 0x00, 0x00, 0x07, 0xFF, 0x83, 0xFE, 0x00, 0x00,
0x00, 0x00, 0x3D, 0xFC, 0x7E, 0x00, 0x03, 0xC0, 0x00, 0x00, 0x07, 0xFF, 0x07, 0xFE, 0x00, 0x00,
0x00, 0x00, 0x78, 0xFC, 0x3E, 0x00, 0x00, 0xE0, 0x00, 0x00, 0x07, 0xFC, 0x1F, 0xFE, 0x00, 0x00,
0x00, 0x00, 0xF0, 0x7E, 0x1E, 0x00, 0x00, 0x70, 0x00, 0x00, 0x07, 0xF0, 0x3F, 0xFE, 0x00, 0x00,
0x01, 0xFF, 0xF0, 0x3E, 0x0E, 0x00, 0x00, 0x78, 0x00, 0x00, 0x07, 0xF0, 0xFF, 0xFE, 0x00, 0x00,
0x7F, 0xFF, 0xFC, 0x1E, 0x04, 0x00, 0x00, 0x78, 0x00, 0x00, 0x03, 0xF0, 0x1F, 0xFE, 0x00, 0x00,
0xFF, 0xFF, 0x7E, 0x1E, 0x00, 0x00, 0x40, 0xFC, 0x00, 0x00, 0x03, 0xFE, 0x0F, 0xFE, 0x00, 0x00,
0xC0, 0x00, 0x3F, 0x0E, 0x00, 0x00, 0x61, 0xFC, 0x00, 0x00, 0x03, 0xFF, 0xDF, 0xFC, 0x00, 0x00,
0xC0, 0x00, 0x0F, 0x06, 0x00, 0x00, 0xC3, 0xEE, 0x00, 0x00, 0x01, 0xFF, 0xFF, 0xFC, 0x00, 0x00,
0xE0, 0x20, 0x07, 0x80, 0x00, 0x01, 0xC3, 0x8E, 0x00, 0x00, 0x03, 0xFF, 0xFF, 0xF8, 0x00, 0x00,
0x71, 0xE0, 0x03, 0x80, 0x00, 0x67, 0x80, 0x0E, 0x00, 0x00, 0x07, 0xFF, 0xFF, 0xF0, 0x00, 0x00,
0x70, 0xE0, 0x01, 0x80, 0x00, 0x7F, 0x00, 0x1F, 0x00, 0x00, 0x02, 0x7F, 0xFF, 0xF0, 0x00, 0x00,
0x38, 0x60, 0x00, 0x00, 0x00, 0x3C, 0x00, 0x7F, 0x00, 0x00, 0x00, 0x3F, 0xFF, 0xC0, 0x00, 0x00,
0x1C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x1F, 0xFF, 0x80, 0x00, 0x00,
0x0E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xFF, 0xF0, 0x00, 0x00, 0x07, 0xFE, 0x00, 0x00, 0x00,
0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x03, 0x80, 0x00, 0x00, 0x30, 0x00, 0x00, 0x07, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x01, 0xC0, 0x00, 0x00, 0xF0, 0x00, 0x00, 0x07, 0xE7, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x01, 0xC0, 0x00, 0x00, 0xE0, 0x00, 0x00, 0x07, 0xC3, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x01, 0x80, 0x00, 0x80, 0x10, 0x00, 0x00, 0x07, 0xC7, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x03, 0x80, 0x01, 0x80, 0x18, 0x80, 0x00, 0x05, 0xC7, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x03, 0x80, 0x01, 0x80, 0x17, 0x00, 0x00, 0x0D, 0x87, 0xBC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x01, 0x80, 0x03, 0x80, 0x10, 0x00, 0x00, 0x0D, 0x07, 0x1C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x01, 0x80, 0x8F, 0x00, 0x30, 0x00, 0x00, 0x18, 0x0E, 0x3E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x01, 0x80, 0xFE, 0x00, 0x60, 0x00, 0x00, 0x18, 0x00, 0x3E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x01, 0xC0, 0x78, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x7F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x01, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x01, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x00, 0xE3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, 0x00, 0x03, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x01, 0xF8, 0x00, 0x0F, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x7F, 0xE0, 0x00, 0x00, 0x00, 0x03, 0xBC, 0x00, 0x1F, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x7F, 0xC0, 0x00, 0x00, 0x00, 0x07, 0x1E, 0x00, 0x1F, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x3F, 0x80, 0x00, 0x00, 0x00, 0x0E, 0x0E, 0x00, 0x0F, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x3E, 0x04, 0x00, 0x00, 0x00, 0x1F, 0x06, 0x00, 0x01, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x1E, 0x1C, 0x00, 0x00, 0x00, 0x3F, 0x82, 0x00, 0x01, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x0F, 0x3C, 0x00, 0x00, 0x00, 0xE1, 0xC0, 0x00, 0x01, 0x80, 0x1F, 0xFF, 0xFF, 0xFF, 0xC0,
0x00, 0x07, 0xFC, 0x00, 0x00, 0x03, 0xC0, 0xC0, 0x00, 0x01, 0x8F, 0xFF, 0xFF, 0xFF, 0xFF, 0xF8,
0x00, 0x03, 0xF8, 0x00, 0x00, 0x0F, 0xE0, 0x40, 0x00, 0x01, 0xFF, 0xFF, 0xFF, 0xFB, 0x2F, 0xFC,
0x00, 0x01, 0xF8, 0x00, 0x00, 0x3F, 0xF0, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x07, 0xF8, 0x07, 0xFE,
0x00, 0x01, 0xDF, 0x80, 0x07, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x70, 0x7F, 0x07, 0xFC, 0x07, 0xFE,
0x00, 0x01, 0xCF, 0xFF, 0xFF, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x70, 0x7F, 0x83, 0xFC, 0x03, 0xFE,
0x00, 0x01, 0x8C, 0x3F, 0xEF, 0x80, 0x00, 0x00, 0x00, 0x00, 0xF8, 0x3F, 0x83, 0xFC, 0x03, 0xFE,
0x00, 0x01, 0x88, 0x00, 0x07, 0x80, 0x00, 0x00, 0x00, 0x01, 0xF8, 0x3F, 0x83, 0xFC, 0x03, 0xFE,
0x00, 0x01, 0xC0, 0x00, 0x07, 0x08, 0x00, 0x00, 0x00, 0x01, 0xF8, 0x3F, 0x03, 0xFC, 0x07, 0xFC,
0x00, 0x01, 0xC0, 0x04, 0x47, 0x1C, 0x30, 0x60, 0x00, 0x7B, 0xF8, 0x7F, 0x07, 0xF8, 0x07, 0xF8,
0x00, 0x00, 0xFF, 0x8C, 0x4F, 0x9C, 0x79, 0xE0, 0x03, 0xFF, 0xF8, 0x7E, 0xFF, 0xFB, 0xFF, 0xE0,
0x00, 0x00, 0x7F, 0xDE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x80,
0x00, 0x00, 0x3F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x03, 0xFF, 0xFF, 0xFF, 0xFF, 0xF0, 0x00,
0x00, 0x00, 0x00, 0xFD, 0xB8, 0xFF, 0xFE, 0x0F, 0xF0, 0x00, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00
};
 
 
 
const uint8_t VU_meter_distiortion_128x64[] U8G_PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x06, 0x00, 0x30, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x12, 0x09, 0xC0, 0x10, 0x90, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x12, 0x09, 0xC0, 0x10, 0x90, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x03, 0x30, 0x10, 0x0C, 0x07, 0xC0, 0x10, 0x90, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x01, 0x48, 0x20, 0x12, 0x01, 0xC0, 0x10, 0x90, 0x03, 0x80, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x01, 0x48, 0x20, 0x0C, 0x06, 0x00, 0x10, 0x60, 0x00, 0x40, 0x00, 0x00, 0x00,
0x00, 0x03, 0x8F, 0x01, 0x48, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00,
0x00, 0x00, 0x50, 0x81, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x07, 0x80, 0x00,
0x00, 0x01, 0xD0, 0x80, 0x00, 0x00, 0x04, 0x02, 0x00, 0x20, 0x40, 0x03, 0x80, 0x04, 0x00, 0x00,
0x00, 0x02, 0x10, 0x80, 0x00, 0x10, 0x04, 0x02, 0x04, 0x20, 0x40, 0x00, 0x00, 0x07, 0x00, 0x00,
0x00, 0x02, 0x10, 0x80, 0x00, 0x10, 0x04, 0x02, 0x04, 0x20, 0x40, 0x00, 0x00, 0x07, 0x00, 0x00,
0x00, 0x03, 0xCF, 0x00, 0x08, 0x10, 0x04, 0x02, 0x04, 0x40, 0x88, 0x00, 0x00, 0x00, 0x80, 0x00,
0x00, 0x00, 0x00, 0x00, 0x08, 0x10, 0x04, 0x02, 0x04, 0x40, 0x88, 0x82, 0x00, 0x07, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x04, 0x08, 0x04, 0x02, 0x04, 0x40, 0x90, 0x82, 0x00, 0x00, 0x01, 0x00,
0x00, 0x00, 0x07, 0x08, 0x04, 0x08, 0x1F, 0xFF, 0xFF, 0xE1, 0xF1, 0x02, 0x00, 0x00, 0x01, 0x00,
0x00, 0x00, 0x07, 0x84, 0x02, 0x0F, 0xE0, 0x00, 0x00, 0x1D, 0xFF, 0x04, 0x20, 0x08, 0x01, 0x00,
0x07, 0xF0, 0x00, 0xC4, 0x03, 0xF0, 0x00, 0x00, 0x00, 0x01, 0xFF, 0xF4, 0x20, 0x10, 0x0F, 0xE0,
0x00, 0x00, 0x00, 0x42, 0x3C, 0x00, 0x08, 0x01, 0xC0, 0x00, 0x3F, 0xFF, 0x40, 0x10, 0x01, 0x00,
0x00, 0x00, 0x00, 0x42, 0x3C, 0x00, 0x08, 0x01, 0xC0, 0x00, 0x3F, 0xFF, 0x40, 0x10, 0x01, 0x00,
0x00, 0x00, 0x18, 0x63, 0xC0, 0x00, 0x08, 0x01, 0xC0, 0x02, 0x00, 0xFF, 0xE0, 0xE0, 0x01, 0x00,
0x00, 0x00, 0x38, 0x3C, 0x00, 0x80, 0x00, 0x00, 0x00, 0x02, 0x00, 0x0F, 0xFD, 0x00, 0x01, 0x00,
0x00, 0x00, 0x3F, 0xE0, 0x00, 0x80, 0x76, 0x0E, 0x30, 0x00, 0x00, 0x00, 0xFF, 0xE0, 0x00, 0x00,
0x00, 0x00, 0x1F, 0x00, 0x00, 0x00, 0x69, 0x03, 0xC8, 0x66, 0x60, 0x00, 0x1F, 0xF8, 0x00, 0x00,
0x00, 0x00, 0x60, 0x00, 0x06, 0x60, 0x19, 0x05, 0xC8, 0x29, 0x90, 0x00, 0x03, 0xFF, 0x00, 0x00,
0x00, 0x03, 0x80, 0x80, 0x01, 0x90, 0x76, 0x04, 0x30, 0x29, 0x90, 0x00, 0x00, 0x1F, 0xC0, 0x00,
0x00, 0x0C, 0x00, 0x40, 0x03, 0x90, 0x00, 0x00, 0x00, 0x26, 0x60, 0x00, 0x00, 0x07, 0xF0, 0x00,
0x00, 0x30, 0x00, 0x00, 0x06, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFC, 0x00,
0x00, 0x30, 0x00, 0x00, 0x06, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFC, 0x00,
0x00, 0x40, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3F, 0x80,
0x01, 0x80, 0x00, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x00,
0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00,
0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x1F, 0x01, 0x81, 0xC1, 0xF8, 0x0F, 0x01, 0xF0, 0x7E, 0x0C, 0x07, 0x80, 0xC3, 0x00, 0x00,
0x00, 0x19, 0x81, 0x83, 0x20, 0x60, 0x19, 0x81, 0x98, 0x18, 0x0C, 0x0C, 0xC0, 0xE3, 0x00, 0x00,
0x00, 0x18, 0xC1, 0x83, 0x00, 0x60, 0x30, 0xC1, 0x98, 0x18, 0x0C, 0x18, 0x60, 0xF3, 0x00, 0x00,
0x00, 0x18, 0xC1, 0x83, 0x80, 0x60, 0x30, 0xC1, 0x98, 0x18, 0x0C, 0x18, 0x60, 0xD3, 0x00, 0x00,
0x00, 0x18, 0xC1, 0x81, 0xC0, 0x60, 0x30, 0xC1, 0xF0, 0x18, 0x0C, 0x18, 0x60, 0xDB, 0x00, 0x00,
0x00, 0x18, 0xC1, 0x80, 0xE0, 0x60, 0x30, 0xC1, 0xB0, 0x18, 0x0C, 0x18, 0x60, 0xCB, 0x00, 0x00,
0x00, 0x18, 0xC1, 0x80, 0x60, 0x60, 0x30, 0xC1, 0x98, 0x18, 0x0C, 0x18, 0x60, 0xCF, 0x00, 0x00,
0x00, 0x19, 0x81, 0x82, 0x60, 0x60, 0x19, 0x81, 0x98, 0x18, 0x0C, 0x0C, 0xC0, 0xC7, 0x00, 0x00,
0x00, 0x1F, 0x01, 0x81, 0xC0, 0x60, 0x0F, 0x01, 0x98, 0x18, 0x0C, 0x07, 0x80, 0xC3, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
 
 
void setup() {
 
  //setup IO
  pinMode(FOOTSWITCH, INPUT_PULLUP);
  pinMode(TOGGLE, INPUT_PULLUP);
  pinMode(PUSHBUTTON_1, INPUT_PULLUP);
  pinMode(PUSHBUTTON_2, INPUT_PULLUP);
  pinMode(LED, OUTPUT);
  pinMode(6, OUTPUT); //PWM0 as output
  pinMode(7, OUTPUT); //PWM1 as output
 
  // setup ADC
  ADMUX = 0x60; // left adjust, adc0, internal vcc
  ADCSRA = 0xe5; // turn on adc, ck/32, auto trigger
  ADCSRB = 0x00; // ADC free running mode
  DIDR0 = 0x01; // turn off digital inputs for adc0
 
  // setup PWM
  TCCR4A = (((PWM_QTY - 1) << 5) | 0x80 | (PWM_MODE << 1)); //
  TCCR4B = ((PWM_MODE << 3) | 0x11); // ck/1
  TIMSK4 = 0x20; // interrupt on capture interrupt
  ICR4H = (PWM_FREQ >> 8);
  ICR4L = (PWM_FREQ & 0xff);
  DDRB |= ((PWM_QTY << 1) | 0x02); // turn on outputs
  sei(); // turn on interrupts - not really necessary with arduino
  }
 
void loop() 
{
  //Turn on the LED and write the OLED if the effect is ON.
  if (digitalRead(FOOTSWITCH)) 
  {
 
    digitalWrite(LED, HIGH); //light the LED
    u8g.firstPage(); 
    do {   
      u8g.drawBitmapP( 0, 0,16,64, VU_meter_distiortion_128x64); //16x8=128
      u8g.drawLine(64,60,128-(distortion_threshold>>8), 10);
      u8g.setPrintPos(70, 64); 
   u8g.setFont(u8g_font_helvR12r); 
   u8g.print(distortion_threshold);
 
 
  }while( u8g.nextPage() );
  }
    else  
  {  
  if(count<100)
  {
    digitalWrite(LED, LOW); // switch-off the LED
    u8g.firstPage(); 
    do {   
      u8g.drawBitmapP( 0, 0,16,64, sleeping_cat128x64); //16x8=128
 
     } while( u8g.nextPage() );
count++;
  }   
 
  }
}
ISR(TIMER4_CAPT_vect) 
{
  // get ADC data
  ADC_low = ADCL; // you need to fetch the low byte first
  ADC_high = ADCH;
  //construct the input sumple summing the ADC low and high byte.
  input = ((ADC_high << 8) | ADC_low) + 0x8000; // make a signed 16b value
 
counter++; //to save resources, the pushbuttons are checked every 1000 times.
if(counter==1000)
{ 
counter=0;
if (!digitalRead(PUSHBUTTON_1)) {
  if (distortion_threshold<32768)distortion_threshold=distortion_threshold+150; //increase the vol
    digitalWrite(LED, LOW); //blinks the led
    }
 
    if (!digitalRead(PUSHBUTTON_2)) {
  if (distortion_threshold>0)distortion_threshold=distortion_threshold-150; //decrease vol
  digitalWrite(LED, LOW); //blinks the led
    }
}
 
//the input signal is 16bits (values from -32768 to +32768
  //the value is clipped to the distortion_threshold value
    if(input>distortion_threshold) input=distortion_threshold;
    else if(input<-distortion_threshold) input=-distortion_threshold;
 
 
  //write the PWM signal
  OCR4AL = ((input + 0x8000) >> 8); // convert to unsigned, send out high byte
  OCR4BL = input; // send out low byte
}

Here's the "Snoozing cat" i found here. I think this is the latest version, am i correct?

______________________________________________________________________________________
Oh yes, just think about an oscilloscope too. with stable Volts/Division and changeable +/- with those two switches, oh god... that would be so much fun with this pedal. i'm loving this more and more...
Desperate electronics enginner | Passionate audio hobbyist.
The administrator has disabled public write access.

Arduino FFT Spectrum Analyzer with pedalSHIELDMEGA 1 month 1 week ago #1764

  • Ray
  • Ray's Avatar
  • OFFLINE
  • Moderator
  • Posts: 615
  • Thank you received: 138
  • Karma: 38
Sorry for my lack of english. I meant after all effects we scroll, finally get to the frequency domain utility and monitoring our signal. And doesn't matter there's no sound on output this time.
Yes, I got it, I think that it is a great idea.

And yes the CAT code is the one you have.
The administrator has disabled public write access.
Time to create page: 0.216 seconds
Powered by Kunena Forum
Joomla SEF URLs by Artio