You are viewing an older revision! See the latest version

Mbed Guitar Pedal

Mbed Guitar Pedal

BY: Shahnawaz Khan, Wes Adams

Mbed Guitar Pedal is an emulation of delay pedal. Its a device that adds echo to the guitar's signal before the signal before the signal is amplified. The length of the echo is determined by the size of the buffer in the program. As the guitar is played, the buffer takes in the signals through AnalogIn and is played to the speaker via AnalogOut. The buffer is filled again, but it is combined with a reduced amplitude of the previous buffer.

Requirements

  • Mbed
  • Protoboard
  • Wires to connect
  • Potentiometer
  • Capacitors
  • Op amps
  • Resistors

Circuit Design

/media/uploads/skhan81/circuit.png

Code

main.cpp

#include "mbed.h"

#define MAX_DELAY   30000
#define MIN_DELAY   50

#define MAX_GAIN    25
#define MIN_GAIN    2

/* ADC for the microphone/input, DAC for the speaker/output */
AnalogIn mic(p19);
AnalogOut speaker(p18);
/* Two potentiometer voltage dividers for the delay/gain control knobs */
AnalogIn delay_knob(p15);
AnalogIn gain_knob(p16);

unsigned char buffer[MAX_DELAY];
unsigned short temp;

/* inv_gain = 1 / gain; it's faster to avoid floating point during the main loop */

int inv_gain = 3;

int delay = MAX_DELAY;

void read_knobs(void) {
    delay = delay_knob*MAX_DELAY;
    //gain = gain_knob*MAX_GAIN;
    if (delay < MIN_DELAY)
        delay = MIN_DELAY;
    /*if (gain < MIN_GAIN)
        gain = MIN_GAIN;
    if (gain == MAX_GAIN)
        gain -= 1;*/
}

int main() {
    int i;
    /* Fill up the sample buffer first */
    for (i = 0; i < delay; i++){
        temp = mic.read_u16();
        buffer[i] += (temp & 0xff);
        }
        
    for (i = 0; ; ) {
        /* Multiply old data by the gain, add new data */
        temp = mic.read_u16();
        buffer[i] = buffer[i]/inv_gain + (temp & 0xff);
        /* Write to speaker */
        temp = buffer[i] & 0x00ff;
        speaker.write_u16(temp);
        /* Increment index and wrap around, effectively only using "delay" length of the buffer */
        i = (i+1) % delay;
        /* Occasionally read the knobs */
        //if (i == 0)
            //read_knobs();
    }
}

Project Demonstration


All wikipages