PU-2: adding a display

The fcb1010 has a numerical display made of 3 digits. It also utilizes a series of LEDs to give more info about its current state. At best, this is an arcane way of doing things, like trying to program a computer using a old rotary telephone. At its worst, it does make you hate the FCB1010.

I will be writing a Mac/PC/Linux interface as I go along, but certain functions are better accomplished on the device itself (very few!)

During prototyping, I will be using an alphanumeric display, made of 2 lines by 16 characters each. I’m debating whether to add a numerical display, either a simple one similar to the one used now on the FCB1010, or a useful one like the one below. Adding the display is trivial, but expensive.

This display, form an old Digitech GNX3000, is ideal: 8 alpha-numeric 14-segments digits and 2 contrasting numerical digits. The entire display can be run from a single chip… but that chip costs 20$, in quantities of 25! Add 15$ for the set of digits…

Driving a 3 digit display, directly from the Arduino using a serial interface and one digital pin can be done for 13$.

Posted in Arduino, Pedal board, PU-2 | Tagged , , | 7 Comments

PU-2: PIN assigments and some testing

It’s good to have a Mega! Plenty of pins for the prototype. Some of the digital pins are hidden by the shield I made for the connectors.

As far as coding goes, programming the PU-2 is easier than programming the PU-1. The switches are all assigned to an independent digital pin. Each can effectively be debounced in software. The FCB1010 switches are all tied together on one side. The other contact of each switch is tied to a digital pin. Defining that pin as INPUT and doing a digitalWrite on it turns on the internal pull-up resistor of the Arduino:

Be careful about which pin is turned into INPUT or OUTPUT, otherwise you will short them.

  int switchMinus16 = 35;
  pinMode(switchMinus16, OUTPUT);
  digitalWrite(switchMinus16, LOW);
  int switchMinus712 = 52;
  pinMode(switchMinus712, OUTPUT);
  digitalWrite(switchMinus712, LOW);

  for(int j = 0; j <= 11; j++){
    pinMode(switches[j], INPUT);
    digitalWrite(switches[j], HIGH);

For the prototype, I decided to limit the parts count. All LEDs are tied to one 330 ohms resistor that is connected in series with +5 volts.

The code below just defines the pins as OUTPUT and then, as a quick test, lights each LED for 250 ms. Then, the pin is set to HIGH, so the LED is turned off. The digital pin is, in effect, supplying GROUND to the LED when low, creating a simple +_resistor_LED_- circuit.

  for(int i = 0; i <= 11; i++){ // LED pins as OUTPUT
    pinMode(led[i], OUTPUT);
    digitalWrite(led[i], LOW);
    delay(250);                // Just a quick test to see
    digitalWrite(led[i],HIGH); // If everything is working
  }

Note that you can’t (or shouldn’t) turn more than one LED on at a time. As a test, I have used the “persistence of vision” (POV) principle with good results:

digitalWrite(pin1, LOW); // Turn LED1 on
digitalWrite(pin1, HIGH);// then off
digitalWrite(pin2, LOW); // Turn LED2 on
digitalWrite(pin2, HIGH);// then off

If the code is fast enough, you eyes won’t see the LEDs blink.

Posted in Arduino, FCB1010, Pedal board, PU-2 | Tagged , , , | Leave a comment

PU-2: emulating the FCB1010!

The PU-2 is now able to emulate pretty much everything a stock FCB1010 can do. I was actually able to send and receive sysex data to/from iFCB, a programming software available on the Mac.

One thing that the PU-2 doesn’t do is let the user program it using it’s own foot switches. It was decided early on the the PU-2 would be programmed from the computer/portable device.
So, the next step is developing my own programming interface for the PU-2; it’s about to do a lot more than the FCB1010!

Posted in Arduino, FCB1010, Pedal board, PU-2 | Tagged , , , , | Leave a comment

PU-2: New brain – Arduino Mega

The FCB1010/PU-2 has a new brain. The Arduino Mega (clone) has been connected in place of the main board.

I have removed: the power transformer, the mains/120 volts plug and the on/off switch, because the PU-2 will be bus-powered.

It was a straightforward affair: no new connections were made, no new switches installed. But the connections weren’t done without challenges. As can be seen on the photo above, I had to assemble the cables linking the foot switch boards to the Arduino. This called for a lot of research for the proper connectors: the ones used in the FCB1010 are 2.00 mm pitch. The connectors used on the Arduino, and pretty much everything else around here, are 2.54 mm pitch (0.10″). So I hand built the 14 pin cables using rather expensive connectors (thanks digikey!). I wanted to be able to connect everything else in the FCB1010 using the connectors already in place, so I also had to find matching connectors for the Midi interface, the expression pedals, the switchable jacks, and various LEDs. All 2.0 mm…

The little board on the right of the Arduino is just used as a connecting platform for the various cables. It also shows the single LED resistor used to drive the 12 LEDs of the board. More on that later.

Why an Arduino MEGA?

As this is a prototype, it has to let me quickly modify anything software and hardware. The Mega has 54 digital input/output pins directly accessible on the board. It also has 16 analog input pins. The regular Arduino boards have one set of serial transmit/receive pins. The Mega has 4 sets.

The two cables connecting the switch/LED boards require 25 pins, already more than can be provided by the Arduino Uno/Diecimila/Duemilanove.

Of course, I could have used mutiplexers/shift registers/LED drivers/etc! But this is a prototype. The final version will be much more efficient, pin wise.

LED driving

There are 10 LEDs on the switch boards. Two more are associated with the expression pedals. All have theirs + pins tied together. My idea is to use a single 330 ohms resistor to drive them. This first version on the PU-2 will only turn one LED on at a time.

So, now, let’s start coding!

Posted in Arduino, FCB1010, Pedal board, PU-2 | Tagged , , , , | 1 Comment

FCB1010 – PU-2: Requirements and Wish List

I’ve identified some requirements for my second pedal board based on the Behringer FCB1010. Here’s a list for now:

  1. USB connection. This is a must, for fast and efficient programming and reprogramming. USB also makes it a lot easier to have bi-derectional communication with a computer, be it a Mac, PC, Linux, iPad, iPhone, etc.
  2. Emulate everything that the stock FCB1010 is doing now. That includes recceiving and sending Sysex commands.
  3. Emulate the Apogee GIO functionality. I have done this with the PU-1, although it is still a work in progress. On top of this, It should be able to emulate the GIO functionality in a PC or Linux environment.
  4. Be reliable and field-maintainable. Everything I build is rock solid. But I also want to be able to fix it anywhere, anytime if something happens…
  5. Phantom power: Since I’m using USB, the board will be powered that way. It will also accept a standard 9 volt pedal feed.

These requirements are a start. As soon as this first part is done, I will start adding functionalities. Examples:

  1. Time delayed midi sends: Pressing a pedal can send a midi command and releasing it will send another one. But the second message you be time delayed.
  2. Cancelling previous presses: pressing a different switch could send midi commands to cancel previous presses. This will be useful to turn stomp boxes on and off.
  3. Switches can have toggle or momentary functionality.

That’s what I will work on right away.

The prototyping is done using an Arduino Mega micro-controller. It’s easy to program and modifying the hardware is also (nearly) trivial.

 

Please, use the comment area to send ideas for functions that you would like to see in the board. Don’t be shy to ask any question. Or if you are… use the email link on the right side of the screen!

Posted in Arduino, FCB1010, Pedal board, PU-2 | Tagged , , | 1 Comment

Now, THAT is cool! The Alesis iO Dock

Update 16/1/31: The Alesis iO Dock has been retired by Alesis. It was replaced by the iO Dock II which is also deprecated. Oh well…

 

This is definitely something I will look at in detail when it becomes available.I’m already using my iPad with keyboards, microphones and my guitar plugged in. Also, I use TouchOSC to communicate using wireless with the computer. This might save me a lot of trial and error by using direct midi communication with the computer and instruments. Of course, if I can find a way to emulate it with an Arduino…

From the iO Dock page:

The iO Dock is the first device that enables anyone with an iPad to create, produce, and perform music with virtually any pro audio gear or instruments. The iO Dock is a universal docking station specifically designed for the iPad, and it gives musicians, recording engineers, and music producers the connectivity they need to create and perform with iPad. Connect all your pro audio gear to virtually any app in the App Store with the iO Dock.

The main features:

  • The world’s first pro audio dock for iPad
  • Connect microphones and instruments including guitar, studio monitors, PA speakers, headphones, and MIDI controllers
  • Universal device works with virtually every audio and MIDI app in the App Store; Core MIDI compliant
  • Perform, craft, create and play back music in virtually any conceivable manner or location
  • Video output for connection to TVs and projectors
  • Inputs: two combo XLR-1/4″ for use with audio gear, instruments, and computer audio
  • Input channel gain controls and switchable phantom power for use with condenser microphones
  • Guitar-direct switch for use with amplifier- and effects-modeling app
  • Outputs: pair 1/4″ and 1/4″ headphone with separate volume controls
  • Control: MIDI In, MIDI Out, USB MIDI, and assignable 1/4-inch footswitch input

 

Posted in Music equipment | Tagged , | Leave a comment

PU-1: Emulating the Apogee Gio, Part 2

I have completed the second phase of this project. The PU-1 can now send commands to GarageBand/Logic/Mainstage and receive commands and other information using Midi commands (but not from GarageBand). Part 2 did not require more electronics. All additional changes were made in software.

WARNING: I first picked up a guitar a few months ago, so I know it’s rough!

The process is accomplished in two steps: First, the software running on the computer (Mac, PC or Linux)(Mac in my case at this point) has to be told how and what to expect from the pedal board. It also has to be told what to send to the pedal board. Second, the pedal board has to be told what to do with the information received from the computer.
For example, the Apogee GIO received codes from the software telling it which effect is on (or off) and actually which pedal board is being used. Since I decided to only use Midi, I’m receiving midi info from Logic or Mainstage and the software handles it. At this point, receiving a valid code from the computer makes a LED blink corresponding to the last pedal pressed. Of course, the GIO uses colored lights that match the color of the stompboxe used in the software. The PU-1 V2 will have colored LEDs too.

The proof of concept, the PU-1 V1.0, is now complete. I will start to work on the Behringer FCB1010 now. The PU-1 will still serve as a test bed.

Posted in Arduino, Pedal board | Tagged , , , , | Leave a comment

PU-1: Let’s do MIDI

After days spent trying to find reliable ways to get Midi data from the pedal board to the computer,  and more days trying to get data from the computer to the pedal board, the proverbial shovel finally hit me square in the face. This is what happened:

The PU-1 is using an Arduino to process signals from its pedals and switches. Since I wanted to send data to the computer for more interaction, I hacked a USB-Midi dongle to receive Midi data from the Arduino’s TX (transmit) pin. It worked quite well, but would be susceptible to the intermittent bug, where the communication would seem to be out of phase and it would only send invalid Midi data.

Then, it was time to receive Midi data from the computer. The goal here is to allow the computer to control, live, the equipment linked to the pedal board. The general idea was to get Midi commands from the USB-Midi dongle. The problem I had (many days), was to design a system that would receive the Midi signal and use an opto-isolator to follow the midi.org recommendations. Right from the get-go, I erred by forgetting to use the opto-isolator. I then decided to use the Midi  breakout board that I have, with an unhacked USB-Midi dongle. It worked perfectly! So I figured my hacked dongle was broken.

The whole idea is to send digital data from the Arduino to the USB port of the computer in such a way that the computer receives Midi data. The other way around, I want to send midi data to a USB port and let the Arduino read it. Using the dongle, I have to add a pile of electronics to the (apparently) simple data path.  So, I took a look at the USB-Midi dongle again: Apart from the opto-isolator and a bunch of capacitor, resistors and one or two transistors/logic inverters, the only important piece of hardware there is a chip (IC). The IC is an MFM0860. According to one manufacturer, this chip will (their words, not mine…):

Key Specifications/Special Features:

  • Features:
  • 1, full-speed USB device interface, compatible with USB20. Norms. External components, only crystals and capacitors.
  • 2, providing 16 Midi input channels and 16 output channels Midi.
  • 3, in line with the relevant specifications, the computer terminal without having to install drivers windows2000/XP below can be used directly.
  • 4, input / output in line with TTL level, can be directly connected to Microcontroller, support plus optical coupling for transmission.
  • 5, using lead-free SSOP-20 package, ROHS.
  • 6, supports all types of organ market

So, this is when the shovel hit. Beside the fact that it “supports all types of organ”(?!), the inputs and outputs are TTL. Mmmmhh. What if I could connect to the “TTL”before the signal had to go through the “midi” part of the dongle?

At risk here was a perfectly good Arduino and a USB-Midi dongle. The Arduino is extremely resistant to electrical abuse. It’s made that way. I wasn’t so certain about the dongle. But I paid $6 for it and I figured… what the hell, let’s do it for science! Besides, let’s think about the connections: the dongle is connected to the computer using USB. It is safe to assume that it uses 5 volts, and the IC is 5 volts too, since I could not find anything that looked like a voltage divider. Because it’s TTL compatible, it is doubly safe to assume it works on 5 volts internally. The dongle is also connected to the Arduino. In fact, I use the dongle to power the Arduino, which gets its 5 volts from the USB power bypass I incorporated in the dongle.

I started with a simple Arduino sketch that sends a midi command through its TX pin (pin 2) when I press a button. I then started to touch the dongle at different points with a wire linked to the TX pin. I started from the “IN” connector inward. At some point, the dongle started transmitting data to the computer. Midi data. Yeah!

I then used a small program on the computer to send Midi data to that USB port. I started touching different points on the “OUT” side of the dongle with a cable connected to the RX pin of the Arduino. I found several points sending nicely formatted Midi commands. Yeah!

All I needed was to solder short jumpers to the pins of the Arduino. As an added benefit, the Midi INPUT and OUTPUT of the dongle are still operational and can (will) be used to connect to standard midi equipment.

Here’s a closeup of the finished modification:

By the way, here’s the schematic for this dongle (or a very similar one)(Thanks Gerry!):

and the whole datasheet (in Chinese): MFM0860 USB MIDI

Posted in Arduino, Pedal board | Tagged , | 9 Comments

PU-1: Emulating the Apogee GIO, Part 1

The Apogee GIO is a small pedal board expressly made to interface with Apple’s Garageband or Logic. I use Logic for music production and control, as well as for live performance.

Apogee GIO

 

Since the PU-1 is awaiting a purpose in life, I decided to try emulating the functionality of the Apogee GIO. Let’s review the functions:

  1. Stomp box control
  2. Hands Free recording
  3. Patch select
  4. Midi Expression pedal input
  5. USB connection
  6. Guitar Preamp
  7. Headphones amp or Speaker Pre-amp

I can emulate the first five items. For connection to a guitar and headphones, I use a M-Audio Fast Track PRO. Many of you probably own an equivalent USB computer interface. Actually, if you do vocals, you probably already have an interface. While I know that Apogee is known for the high quality of their audio interfaces, the M-Audio fills my need and won’t be updated.

PU-1 with numbered switches

 

1, 2 & 3: Switches and controls

The GIO will automatically know which stompboxes you’re using in Logic or GarageBand. Well… to a maximum of five (four in Mainstage). One feature that is promoted is the ability for the GIO to show the color of the stomp box it’s connected to. This discussion implies that the GIO uses standard Midi CC messages to exchange information with external software. Since I have not installed RGB LEDs on the PU-1 (yet!), I can’t show colored stompbox indicators. Not a big feature, as far as I’m concerned. But the GIO indicates the fact that a particular pedal is in use by using a different intensity for the LED. I could use a different intensity, or I could make the LED blink. I will test both.

The GIO has two rows of switches. My PU-1 has one. I will have to switch functionality by using an extra switch. The top left switch (number 7) will be used to switch the functions of the bottom row (switches 1 to 6). Of course, I when I transfer this to the  FCB1010, I will have enough switches to implement this using one less step.

I like the idea of being able to press a switch to change the sound patch in Logic, so I will use switches 1 and 6 to do this, emulating the corner switches on the GIO.

I will be able to control 4 stomp boxes and, after a press of switch 7, I will be able to send the appropriate codes for Play/stop, Record, forward and Back/Back to Beginning. I will use switch 8 as a Master Mute (Panic Button).

One thing the GIO doesn’t have is a rotary encoder. I will use mine to quickly select patches (turn and click to confirm).

4: Expression pedals

With the GIO, you have to buy separate expression pedals (very specific models). The PU-1 has two!

5: USB connection

The PU-1 was built with USB connection in mind. In fact, I can use two different connections: one to talk directly to the Arduino, the other to send and receive Midi codes.

Programming the Arduino

The toughest part will be controlling the stomp boxes. So let’s start with that one.

In Logic, the stompboxes are assigned to a particular instrument. It is possible to send a midi Control Change (Midi CC) to Logic to affect parameters on the stompbox. They have a “learn” mode. But the idea is to get a feedback from Logic telling the PU-1 if an effect is on or off, or even what a particular value is, in the case of a variable, like a knob. I would like to receive that value to make sure that the pedal board is reflecting the same state as Logic. Otherwise, the programming is quite simple.

Pressing a switch on the PU-1 will send a midi signal to Logic. Logic has a learn mode that allows any(?) variable to be modified by an external midi signal. For example, my M-Audio Oxygen 49 keyboard sends Midi CC 116 when I press the STOP transport button. So if I put Logic in “learn” mode for the STOP function and then press the button on my keyboard, an association is made between the two. Actually, Logic doesn’t care which button I press. I could even be a keyboard note!

So, in the Arduino sketch, I just have to create a Midi code table and have logic respond to these codes. Of course, each code is linked to a switch, an encoder or a pedal. In turn, I would like logic to send some confirmation signal when it has responded to a midi command. That would prevent de-synchronization between the state of the pedal board and the actual effect in Logic. I haven’t found a way to send the signal from Logic to the pedal board, but I was given a way to do it in Mainstage.

Since I decided to keep switches 1 & 6 for Next/Previous Patch, I have to select 4 transport. I will use Loop, Stop, Play and Record. Function Selection is on Switch 7, Master Mute on Switch 8, Wah/Modulation is activated with Switch 9 (toe down on left Expression pedal). Then I’ve assign CC values to all the switches and pedals. That choice is based on previous experience and compatibility with other equipment. The CC values could be anything, really.

Once the code is uploaded to the Arduino, it is used as a Midi source for Logic/Mainstage.

I will post a video soon. The code is here. It has not been optimised and is not using the Arduino Midi library yet.

Posted in Arduino, Pedal board | Tagged , , | 3 Comments

PU-1: Complete V 1.0

The PU-1 is complete, at least in its prototyping phase. The connection board is done and the external Arduino/Shield is attached.

In this picture, the PU-1 is powered by a 9 volt battery. At the top is the Arduino with the connection shield and the connection ribbon. I removed the USB connector from this picture. While doing some tests, I also attached the midi-to-USB converter to the Arduino pins through the shield.

The connection board

The connection board is used to assemble the various components that the PU-1 needs to communicate with the rest of the system.

At the top of the board, a 20 pin insert is used to connect to a ribbon cable, from an old computer. Luckily, the ribbon is terminated with a connector using standard .1″ spacing. There are 6 pins unused on the 20-pin connector: 3 analog and 3 digital pins. Plenty of room for expansion. At the bottom of this board, from left to right, we have:

With as few electronic parts as possible, this board is pretty much indestructible.

The Arduino and Arduino Shield

I use a Spikenzielab Shield Dock. The 20-pin connector on the left connects to all digital pins on the Arduino, except pins 0 & 1, that are used for serial communication (midi). I could have assembled all the electronics used on the little connection board directly on this shield. I chose to have two boards because this shield will probably be used differently as this is only a prototyping pedal board. The part that stays inside the pedal board will not change that much, except when adding new switches and sensors.

The PU-1

Since I’m using a flat ribbon cable, I can re-install the PU-1 bottom cover over it. I use a layer of insulating tape to protect the ribbon. The grey masking tape under the connection board is replaced with an insulation layer (cardboard!) taped to it. I will eventually screw the board to the top plate.

The Arduino Code

Of course, all this works because the Arduino controls the pedal board. This is the code that I’m using during the test stage.

 

/* 
 * First Section: configure the periodical execution of a user 
 * defined function (Interrupt service routine) using Timer2. This 
 * example will run the function every 1ms.  
 */

#include <Bounce.h> 

/* Timer2 reload value, globally available */  
unsigned int tcnt2;  

int pin1 = 12;
int pin2 = 11;
int counter = 0;
int oldCounter = 0;

// Instantiate a Bounce object with a 5 millisecond debounce time
// Only pin1 needs to be debounced. It is assumed that pin2
// will be stable when reading pin1
Bounce bouncer1 = Bounce( pin1,5 );

/* Second Section:
Use 3 74HC595 shift registers to display 3 numbers on 
common cathode 7-segments LEDs, and one more 595 to turn a series of
10 LEDs on and off.
This code should work for any digit assembly, but was specifically
used to recuperate the digits of an old Line 6 floor board.
U1 pin 12 is Latch
U1 pin 11 is Clock
U1 pin 14 is Serial data input.
*/
int LatchPin = 6;
int ClockPin = 5;
int DataPin = 7;
char m[4];
byte data;
byte dataArray[10]; //character segment matrice
int k = 100; //divider for number display
int showLed = 0x00; //led array
int dp1 = 0x00; //connected to LED 1
int dp2 = 0x00; //connected to LED 2
int dp3 = 0x00; //connected to decimal point on digit 1

//definitions for pedals and their LEDs
int express=1;
int oldExpressValue = 0;
int wah=2;
int oldWahValue = 0;
int swresist=0;
int resistValue;
int showTemp = 0;

//third section: MIDI
// general midi notes
char note1 = 60; //Middle C
char note2 = 62; //D
char note3 = 64; //E
char note4 = 65; //F
char note5 = 67; //G
char note6 = 69; //A
char lastCmd[3] = {0x00,0x00,0x00};

//Fourth Section: General setup
int pin13 = 13;

void setup() {
  //setup for the display
  pinMode(LatchPin, OUTPUT);
  pinMode(ClockPin, OUTPUT);
  pinMode(DataPin, OUTPUT);
  //setup for the rotary encoder
  pinMode(pin1, INPUT);
  pinMode(pin2, INPUT);

  Serial.begin(31250);

//This section for the Timer Interrupt

   /* First disable the timer overflow interrupt while we're configuring */  
  TIMSK2 &= ~(1<<TOIE2);  

  /* Configure timer2 in normal mode (pure counting, no PWM etc.) */  
  TCCR2A &= ~((1<<WGM21) | (1<<WGM20));  
  TCCR2B &= ~(1<<WGM22);  

  /* Select clock source: internal I/O clock */  
  ASSR &= ~(1<<AS2);  

  /* Disable Compare Match A interrupt enable (only want overflow) */  
  TIMSK2 &= ~(1<<OCIE2A);  

  /* Now configure the prescaler to CPU clock divided by 128 */  
  TCCR2B |= (1<<CS22)  | (1<<CS20); // Set bits  
  TCCR2B &= ~(1<<CS21);             // Clear bit  

  /* We need to calculate a proper value to load the timer counter. 
   * The following loads the value 131 into the Timer 2 counter register 
   * The math behind this is: 
   * (CPU frequency) / (prescaler value) = 125000 Hz = 8us. 
   * (desired period) / 8us = 125. 
   * MAX(uint8) + 1 - 125 = 131; 
   */  
  /* Save value globally for later reload in ISR */  
  tcnt2 = 131;   

  /* Finally load end enable the timer */  
  TCNT2 = tcnt2;  
  TIMSK2 |= (1<<TOIE2);  
}  

/* 
 * Install the Interrupt Service Routine (ISR) for Timer2 overflow. 
 * This is normally done by writing the address of the ISR in the 
 * interrupt vector table but conveniently done by using ISR()  */  
ISR(TIMER2_OVF_vect) {  
  /* Reload the timer */  
  TCNT2 = tcnt2;  

  bouncer1.update();
  if(bouncer1.risingEdge()){
    oldCounter = counter;
    if (digitalRead(pin2)){
      counter--;
    }
      else{
      counter++;
    }
  }

//End of Timer Interrupt section

//Define character images in an array
  dataArray[0] = 0x3f; // 0
  dataArray[1] = 0x06; // 1
  dataArray[2] = 0x5B; // 2
  dataArray[3] = 0x4F; // 3
  dataArray[4] = 0x66; // 4
  dataArray[5] = 0x6D; // 5
  dataArray[6] = 0x7C; // 6
  dataArray[7] = 0x07; // 7
  dataArray[8] = 0x7F; // 8
  dataArray[9] = 0x67; // 9
}

void loop() 
{
//Read pedal values and show reading from 0 - 127
//need to be calibrated by hand for now. Routine to come
int expressValue = map(analogRead(express),950,85,0,127);
if (expressValue < (oldExpressValue-1) || expressValue > (oldExpressValue+1)) {
  showValue(expressValue);
  oldExpressValue = expressValue;
  midiCmd(0xB0,0x0B, char(expressValue));
}
int wahValue = map(analogRead(wah),950,85,0,127);
if (wahValue < (oldWahValue-1) || wahValue > (oldWahValue+1)) {
  showValue(wahValue);
  oldWahValue = wahValue;
  midiCmd(0xB0,0x07,char(wahValue));
}

//treat resistor value. No switch pressed = 916/1024
//leds 10,8,7 as MSB then6,5,4 and 3 as LSB binaries
//into variable showLed
  resistValue = analogRead(swresist);
  if ((resistValue > 750) && (lastCmd[1] == char(0x90)) && (lastCmd[2] != 0x00)){ //no pedal pressed -> all notes off
    midiCmd(0x90,lastCmd[2],0x00);
    lastCmd[2] = 0x00;
  }

//  Serial.println(resistValue);
  if (resistValue < 10){
     //Tuner ON
     showLed = 0x80;
     delay(500);
     if(digitalRead(pin13) == LOW)
     digitalWrite(pin13,HIGH);
     else
     digitalWrite(pin13,LOW);
  }
  if (resistValue >= 35 & resistValue < 50){
    //Effect control OR Channel Select
    //Using LED 1 & 2
    delay(500); //wait for switch release. Might need interrupt
    if (dp1 == 0x00){ 
     dp1 = 0x80;
     dp2 = 0x00;
     dp3 = 0x00;
    }else {
     dp1 = 0x00;
     dp2 = 0x80;
     dp3 = 0x00;
    }
     showLed = 0x00;
  }
  if (resistValue >= 142 & resistValue < 155){
    if(lastCmd[2] != note1)
    midiCmd(0x90, note1, 0x45);
     showLed = 0x01;
  }     
  if (resistValue >= 205 & resistValue < 215){
    if(lastCmd[2] != note2)    midiCmd(0x90, note2, 0x45);
     showLed = 0x02;
  }
  if (resistValue >= 270 & resistValue < 290){
    if(lastCmd[2] != note3)    midiCmd(0x90, note3, 0x45);
     showLed = 0x04;
  }
  if (resistValue >= 350 & resistValue < 500){
    if(lastCmd[2] != note4)    midiCmd(0x90, note4, 0x45);
     showLed = 0x08;
  }
  if (resistValue >= 575 & resistValue < 585){
    //Enter special mode. Light left Decimal point
     dp1 = 0x00;
     dp2 = 0x00;
     dp3 = 0x80;
  }
  if (resistValue >= 640 & resistValue < 650){
    if(lastCmd[2] != note5)    midiCmd(0x90, note5, 0x45);
     showLed = 0x10;
  }
  if (resistValue >= 710 & resistValue < 720){
    if(lastCmd[2] != note6)    midiCmd(0x90, note6, 0x45);
     showLed = 0x20;
  }

//Getting ready to display values and indicators
  if (counter < 0 || counter > 999)
    counter = 0;
  if (oldCounter != counter){
    showValue(counter);
    midiCmdShort(0xC0,counter);
  }
  oldCounter = counter;
//Show me the number!
  liteUpDisplay();
  delay(5);

} /////END of LOOP

//Prepare array to cascade down shift registers
void showValue(int showNumber) {
  int k = 100;
  for (int i = 2; i >= 0; i--)
  {
    m[i] = showNumber / k;
    showNumber = showNumber - (m[i] * k);
    k = k / 10;
  }
}
//Display 3 digits and one of 3 indicators
void liteUpDisplay(){

  digitalWrite(LatchPin, LOW);
  //rightmost digit. Use | (or) with 0x80 to light led 2
  shiftOut(DataPin, ClockPin, MSBFIRST, dataArray[m[0]] | dp1);   
  //middle digit. Use | (or) to light led 1
  shiftOut(DataPin, ClockPin, MSBFIRST, dataArray[m[1]] | dp2);   
  //lefmost digit. Use | (or) to light decimal point
  shiftOut(DataPin, ClockPin, MSBFIRST, dataArray[m[2]] | dp3);
  //leds 10,8,7 then6,5,4 and 3 as MSB and LSB binaries
  shiftOut(DataPin, ClockPin, MSBFIRST, showLed);
  digitalWrite(LatchPin, HIGH);
  }

// Send a MIDI Command with 3 parts
void midiCmd(char cmd, char data1, char data2) {
  lastCmd[1] = cmd;
  lastCmd[2] = data1;
  lastCmd[3] = data2;
  Serial.print(cmd, BYTE);
  Serial.print(data1, BYTE);
  Serial.print(data2, BYTE);
}
// Send a MIDI Command with 2 parts
void midiCmdShort(char cmd, char data1) {
  lastCmd[1] = cmd;
  lastCmd[2] = data1;
  Serial.print(cmd, BYTE);
  Serial.print(data1, BYTE);
}
Posted in Arduino, Pedal board | Tagged , | Leave a comment