🎹 Timex Synth 🔣

🎹 Timex Synth 🔣

October 21, 2018 DIY / Maker 0

Finally this thing is fun. This 1982 Timex Sinclair 1000 computer always looked rad to us, but never could sound as such, until now. It’s brain has been replaced by a Spark Fun Pro Micro, plus a PT2399 karaoke machine reverb chip, and even a built-in DI. Now it’s a PWM synth+arpeggiator (and 8 bit PCM rompler soon) with a vast expressive toolbox for ghosts blessings.👻

stay tuned on our insta for that future

“source code or it didn’t happen”

arduino pro micro or leonardo sketch:

// music action keyboard deal by woz supposedly, greasy conversation sep 2018
// ZX81 USB Keyboard for Leonardo
// (c) Dave Curran
// 2013-04-27

// Modified with Function keys by Tony Smith
// 2014-02-15

#include <Adafruit_NeoPixel.h>

#define NOTE_B0  31
#define NOTE_C1  33
#define NOTE_CS1 35
#define NOTE_D1  37
#define NOTE_DS1 39
#define NOTE_E1  41
#define NOTE_F1  44
#define NOTE_FS1 46
#define NOTE_G1  49
#define NOTE_GS1 52
#define NOTE_A1  55
#define NOTE_AS1 58
#define NOTE_B1  62
#define NOTE_C2  65
#define NOTE_CS2 69
#define NOTE_D2  73
#define NOTE_DS2 78
#define NOTE_E2  82
#define NOTE_F2  87
#define NOTE_FS2 93
#define NOTE_G2  98
#define NOTE_GS2 104
#define NOTE_A2  110
#define NOTE_AS2 117
#define NOTE_B2  123
#define NOTE_C3  131
#define NOTE_CS3 139
#define NOTE_D3  147
#define NOTE_DS3 156
#define NOTE_E3  165
#define NOTE_F3  175
#define NOTE_FS3 185
#define NOTE_G3  196
#define NOTE_GS3 208
#define NOTE_A3  220
#define NOTE_AS3 233
#define NOTE_B3  247
#define NOTE_C4  262
#define NOTE_CS4 277
#define NOTE_D4  294
#define NOTE_DS4 311
#define NOTE_E4  330
#define NOTE_F4  349
#define NOTE_FS4 370
#define NOTE_G4  392
#define NOTE_GS4 415
#define NOTE_A4  440
#define NOTE_AS4 466
#define NOTE_B4  494
#define NOTE_C5  523
#define NOTE_CS5 554
#define NOTE_D5  587
#define NOTE_DS5 622
#define NOTE_E5  659
#define NOTE_F5  698
#define NOTE_FS5 740
#define NOTE_G5  784
#define NOTE_GS5 831
#define NOTE_A5  880
#define NOTE_AS5 932
#define NOTE_B5  988
#define NOTE_C6  1047
#define NOTE_CS6 1109
#define NOTE_D6  1175
#define NOTE_DS6 1245
#define NOTE_E6  1319
#define NOTE_F6  1397
#define NOTE_FS6 1480
#define NOTE_G6  1568
#define NOTE_GS6 1661
#define NOTE_A6  1760
#define NOTE_AS6 1865
#define NOTE_B6  1976
#define NOTE_C7  2093
#define NOTE_CS7 2217
#define NOTE_D7  2349
#define NOTE_DS7 2489
#define NOTE_E7  2637
#define NOTE_F7  2794
#define NOTE_FS7 2960
#define NOTE_G7  3136
#define NOTE_GS7 3322
#define NOTE_A7  3520
#define NOTE_AS7 3729
#define NOTE_B7  3951
#define NOTE_C8  4186
#define NOTE_CS8 4435
#define NOTE_D8  4699
#define NOTE_DS8 4978

#define NUM_ROWS 8
#define NUM_COLS 5
int maxBri = 255;
int LEDPIN = 2;
int octave = 2;
int boctave = 2;
int sus = 1;
int susmult = 30;
int duty = 0;
int dutymult = 10;
int eff = 0;
bool pitchoct = false;
float pitch = 1;
word key = 0;

Adafruit_NeoPixel strip = Adafruit_NeoPixel(5, LEDPIN, NEO_RGB + NEO_KHZ800);

int colorMap[3][5] =
{
  {0, 0, 0, 0, 50},
  {200, 200, 200, 200, 50},
  {0, 0, 0, 0, 50},
};

int keyMap[NUM_ROWS][NUM_COLS] =
{
  {NOTE_FS1, 'r', NOTE_DS1, NOTE_CS1, 'q'},
  {NOTE_G1, NOTE_F1, NOTE_E1, NOTE_D1, NOTE_C1},
  {NOTE_GS1, NOTE_AS1, 'i', NOTE_CS2, NOTE_DS2},
  {'g', NOTE_AS2, NOTE_GS2, NOTE_FS2, 'a'},
  {NOTE_A1, NOTE_B1, NOTE_C2, NOTE_D2, NOTE_E2},
  {NOTE_B2, NOTE_A2, NOTE_G2, NOTE_F2, 'z'},
  {NOTE_CS3, NOTE_DS3, 'k', NOTE_FS3, 'e'},
  {NOTE_C3, NOTE_D3, NOTE_E3, NOTE_F3, NOTE_G3}
};

int keyMapB[NUM_ROWS][NUM_COLS] =
{
  {NOTE_FS3, 'r', NOTE_DS3, NOTE_CS3, 'q'},
  {NOTE_G3, NOTE_F3, NOTE_E3, NOTE_D3, NOTE_C3},
  {NOTE_GS3, NOTE_AS3, 'i', NOTE_CS4, NOTE_DS4},
  {'g', NOTE_AS4, NOTE_GS4, NOTE_FS4, 'a'},
  {NOTE_A3, NOTE_B3, NOTE_C4, NOTE_D4, NOTE_E4},
  {NOTE_B4, NOTE_A4, NOTE_G4, NOTE_F4, 'z'},
  {NOTE_CS5, NOTE_DS5, 'k', NOTE_FS5, 'e'},
  {NOTE_C5, NOTE_D5, NOTE_E5, NOTE_F5, NOTE_G5}
};

int keyMapC[NUM_ROWS][NUM_COLS] =
{
  {NOTE_FS5, 'r', NOTE_DS5, NOTE_CS5, 'q'},
  {NOTE_G5, NOTE_F5, NOTE_E5, NOTE_D5, NOTE_C5},
  {NOTE_GS5, NOTE_AS5, 'i', NOTE_CS6, NOTE_DS6},
  {'g', NOTE_AS6, NOTE_GS6, NOTE_FS6, 'a'},
  {NOTE_A5, NOTE_B5, NOTE_C6, NOTE_D6, NOTE_E6},
  {NOTE_B6, NOTE_A6, NOTE_G6, NOTE_F6, 'z'},
  {NOTE_CS7, NOTE_DS7, 'k', NOTE_FS7, 'e'},
  {NOTE_C7, NOTE_D7, NOTE_E7, NOTE_F7, NOTE_G7}
};

// Global Variables

int debounceCount[NUM_ROWS][NUM_COLS];

// Define the row and column pins

byte colPins[NUM_COLS] = {4, 5, 6, 7, 8};
byte rowPins[NUM_ROWS] = {3, 14, 15, 16, 18, 19, 20, 21};

// SETUP

void setup()
{
  Serial.begin(9600);      // open the serial port at 9600 bps:
  strip.begin();
  strip.show(); // Initialize all pixels to 'off'
  strip.setBrightness(maxBri);
  randomSeed(analogRead(10));

  for (byte c = 0 ; c < NUM_COLS ; c++)
  {
    pinMode(colPins[c], INPUT);
    digitalWrite(colPins[c], HIGH);


    // Set all pins as inputs

    for (byte r = 0 ; r < NUM_ROWS ; r++)
    {
      pinMode(rowPins[r], INPUT);
    }

  }

  pinMode(A10, INPUT_PULLUP);

}

// LOOP

void loop()
{

  for (int a = 0 ; a < 100 ; a++)
  {

    for (byte r = 0 ; r < NUM_ROWS ; r++)
    {
      // Run through the rows, turn them on

      pinMode(rowPins[r], OUTPUT);
      digitalWrite(rowPins[r], LOW);

      for (byte c = 0 ; c < NUM_COLS ; c++)
      {
        if (digitalRead(colPins[c]) == LOW)
        {
          pressKey(r, c);

        }

      }

      // Turn the row back off

      pinMode(rowPins[r], INPUT);
    }


  }
  lightMove();

}

void pressKey(byte r, byte c)
{

  if (keyMap[r][c] == 'z')
  {
    octave = ++octave;
    if (octave > 3) {
      octave = 2;
    }
  }
  else if (keyMap[r][c] == 'a')
  {
    octave = 1;
  }
  else if (keyMap[r][c] == 'g')
  {
    octave = 2;
  }
  else if (keyMap[r][c] == 'k')
  {
    octave = 3;
  }

  else if (keyMap[r][c] == 'r')
  {
    sus = ++sus;
    if (sus > 5) {
      sus = 1;
    }
    susmult = sus * 30;
    dutymult = (duty * ((susmult / 3) * 2)) + (susmult / 3);
    delay(300);
  }

  else if (keyMap[r][c] == 'q')
  {
    eff = ++eff;
    if (eff >= 30 ) {
      eff = 0;
      sus = 1;
      susmult = 30;
      duty = 0;
      dutymult = 10;
    } else {
      susmult = eff + 18;
      dutymult = eff + 18;
    }
    delay(60);
  }
  else if (keyMap[r][c] == 'i')
  {
    duty = ++duty;
    if (duty > 4 ) {
      duty = 0;
    }
    dutymult = (duty * ((susmult / 3) * 2)) + (susmult / 3);
    delay(300);
  }

  else if (keyMap[r][c] == 'e') {
    eff = 0;
    sus = 1;
    susmult = 30;
    duty = 0;
    dutymult = 10;
    octave = 2;
    delay(60);
  }

  else
  {

    if (octave == 1) key = keyMap[r][c];
    if (octave == 2) key = keyMapB[r][c];
    if (octave == 3) key = keyMapC[r][c];

    float pitchcheck = analogRead(A10);

    if (pitchoct) {
      if (pitchcheck < 650) {
        pitch = 1 + ((500 - (pitchcheck - 150)) / 500);
      } else {
        pitch = 1;
      }
      if (pitch < 1) {
        pitch = 1;
      }
      if (pitch > 2) {
        pitch = 2;
      }
    } else {

      if (pitchcheck < 650) {
        pitch = 1 + (((500 - (pitchcheck - 150)) / 500) / 8);
      } else {
        pitch = 1;
      }
      if (pitch < 1) {
        pitch = 1;
      }
      if (pitch > 1.13) {
        pitch = 1.13;
      }
    }

    Serial.print(pitchcheck);
    Serial.print("\t");
    Serial.print(pitch);
    Serial.print("\n");

    // where the magic happens

    if (key > 0) tone(9, key * pitch, susmult);
    delay(dutymult);

  }
}

void lightMove() {

  if ((duty > 3) && (sus > 4)) {
    if (maxBri == 26) {
      maxBri = 255;
      //if we switch back from dark mode, we then switch to full-octave pitch shift mode,
      // or back to normal semitone pitch shift
      if (pitchoct) {
        pitchoct = false;
      } else {
        pitchoct = true;
      }
    } else {
      maxBri = 26;
    }
    sus = 1;
    susmult = 30;
    duty = 0;
    dutymult = 10;
    strip.setBrightness(maxBri);
  }

  int j = random(0, 4);
  int c = random(0, 3);


  if (random(2) >= 1) {
    colorMap[c][j] = colorMap[c][j] + sus * sus;
    if (colorMap[c][j] >= maxBri) {
      colorMap[c][j] = maxBri - 1;
    }
  } else {
    colorMap[c][j] = colorMap[c][j] - sus * sus;
    if (colorMap[c][j] <= 0) {
      colorMap[c][j] = 1;
    }
  }

  if (eff != 0 ) {
    strip.setPixelColor(random(0, 4), strip.Color(random(1, eff * 7), random(1, eff * 7), random(1, eff * 7)));
    strip.setPixelColor(4, strip.Color(250 - ((octave - 1) * 100), random(1, eff * 7), random(1, eff * 7)));

  } else if (duty != 0) {
    strip.setPixelColor(4, strip.Color(250 - ((octave - 1) * 100), (sus - 1) * 50, (duty) * 50));
    if (duty == 1) {
      strip.setPixelColor(0, strip.Color(colorMap[1][0], colorMap[2][0], colorMap[0][0]));
      strip.setPixelColor(j, strip.Color(colorMap[0][j], colorMap[1][j], colorMap[2][j]));
    }
    if (duty == 2) {
      strip.setPixelColor(1, strip.Color(colorMap[1][1], colorMap[2][1], colorMap[0][1]));
      strip.setPixelColor(j, strip.Color(colorMap[0][j], colorMap[1][j], colorMap[2][j]));
    }
    if (duty == 3) {
      strip.setPixelColor(2, strip.Color(colorMap[1][2], colorMap[2][2], colorMap[0][2]));
      strip.setPixelColor(j, strip.Color(colorMap[0][j], colorMap[1][j], colorMap[2][j]));
    }
    if (duty == 4) {
      strip.setPixelColor(3, strip.Color(colorMap[1][3], colorMap[2][3], colorMap[0][3]));
      strip.setPixelColor(j, strip.Color(colorMap[0][j], colorMap[1][j], colorMap[2][j]));
    }
  } else {
    strip.setPixelColor(j, strip.Color(colorMap[0][j], colorMap[1][j], colorMap[2][j]));
    strip.setPixelColor(4, strip.Color(250 - ((octave - 1) * 100), (sus - 1) * 50, (duty) * 50));
  }

  strip.show();
}

UPDATE – the keypad broke, so some of the keys don’t work anymore BUT
we decided to add midi control, which ended up really cool. so check out the new version, forgive the duplicate buttons, and enjoy the arduino buzz function being controlled by midi:

// music action keyboard deal by woz supposedly, greasy conversation sep 2018
// ZX81 USB Keyboard for Leonardo
// (c) Dave Curran
// 2013-04-27

// Modified with Function keys by Tony Smith
// 2014-02-15

#include "pitches.h"
#include <Adafruit_NeoPixel.h>
#include <MIDIUSB.h>
#include "pitchToFrequency.h"

#define MIDI_CC MIDI_CC_GENERAL1
#define channel 12

#define NUM_ROWS 8
#define NUM_COLS 5
int maxBri = 255;
int LEDPIN = 2;
int octave = 4;
int sus = 1;
int susmult = 30;
int duty = 0;
int dutymult = 10;
int eff = 0;
bool pitchoct = true;
int vib = 0;
bool vibdown = false;
int vibs = 0;
int vibd = 0;
int viblive = 0;
double mpitch = 0;
word key = 0;
bool b1 = true;
bool b2;
bool b3;
bool b4;
bool b5;
byte pitch;
bool midinoteon;
bool freshnote;
int midiup = 2;
bool midion;

const char* pitch_name(byte pitch) {
  static const char* names[] = {"C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"};
  return names[pitch % 12];
}
int pitch_octave(byte pitch) {
  return (pitch / 12) - 1;
}

Adafruit_NeoPixel strip = Adafruit_NeoPixel(5, LEDPIN, NEO_RGB + NEO_KHZ800);

int colorMap[3][5] =
{
  {0, 0, 0, 0, 50},
  {200, 200, 200, 200, 50},
  {0, 0, 0, 0, 50},
};

int keyMap[NUM_ROWS][NUM_COLS] =
{
  {NOTE_FS1, 'r', NOTE_DS1, NOTE_CS1, 'q'},
  {NOTE_G1, NOTE_F1, NOTE_E1, NOTE_D1, NOTE_C1},
  {NOTE_GS1, NOTE_AS1, 'i', NOTE_CS2, NOTE_DS2},
  {'g', 'e', 'k', 'g', 'a'},
  {NOTE_A1, NOTE_B1, NOTE_C2, NOTE_D2, NOTE_E2},
  {'vv', 'cc', 'xx', 'zz', 'z'},
  {NOTE_CS3, NOTE_DS3, 'k', NOTE_FS3, 'e'},
  {'bb',  'g', 'k', 'a', 'e'}
};

int keyMapB[NUM_ROWS][NUM_COLS] =
{
  {NOTE_FS2, 'r', NOTE_DS2, NOTE_CS2, 'q'},
  {NOTE_G2, NOTE_F2, NOTE_E2, NOTE_D2, NOTE_C2},
  {NOTE_GS2, NOTE_AS2, 'i', NOTE_CS3, NOTE_DS3},
  {'g', 'e', 'k', 'g', 'a'},
  {NOTE_A2, NOTE_B2, NOTE_C3, NOTE_D3, NOTE_E3},
  {'vv', 'cc', 'xx', 'zz', 'z'},
  {NOTE_CS4, NOTE_DS4, 'k', NOTE_FS4, 'e'},
  {'bb', 'g', 'k', 'a', 'e'}
};

int keyMapC[NUM_ROWS][NUM_COLS] =
{
  {NOTE_FS3, 'r', NOTE_DS3, NOTE_CS3, 'q'},
  {NOTE_G3, NOTE_F3, NOTE_E3, NOTE_D3, NOTE_C3},
  {NOTE_GS3, NOTE_AS3, 'i', NOTE_CS4, NOTE_DS4},
  {'g', 'e', 'k', 'g', 'a'},
  {NOTE_A3, NOTE_B3, NOTE_C4, NOTE_D4, NOTE_E4},
  {'vv', 'cc', 'xx', 'zz', 'z'},
  {NOTE_CS5, NOTE_DS5, 'k', NOTE_FS5, 'e'},
  {'bb', 'g', 'k', 'a', 'e'}
};

int keyMapD[NUM_ROWS][NUM_COLS] =
{
  {NOTE_FS4, 'r', NOTE_DS4, NOTE_CS4, 'q'},
  {NOTE_G4, NOTE_F4, NOTE_E4, NOTE_D4, NOTE_C4},
  {NOTE_GS4, NOTE_AS4, 'i', NOTE_CS5, NOTE_DS5},
  {'g', 'e', 'k', 'g', 'a'},
  {NOTE_A4, NOTE_B4, NOTE_C5, NOTE_D5, NOTE_E5},
  {'vv', 'cc', 'xx', 'zz', 'z'},
  {NOTE_CS6, NOTE_DS6, 'k', NOTE_FS6, 'e'},
  {'bb', 'g', 'k', 'a', 'e'}
};

int keyMapE[NUM_ROWS][NUM_COLS] =
{
  {NOTE_FS5, 'r', NOTE_DS5, NOTE_CS5, 'q'},
  {NOTE_G5, NOTE_F5, NOTE_E5, NOTE_D5, NOTE_C5},
  {NOTE_GS5, NOTE_AS5, 'i', NOTE_CS6, NOTE_DS6},
  {'g', 'e', 'k', 'g', 'a'},
  {NOTE_A5, NOTE_B5, NOTE_C6, NOTE_D6, NOTE_E6},
  {'vv', 'cc', 'xx', 'zz', 'z'},
  {NOTE_CS7, NOTE_DS7, 'k', NOTE_FS7, 'e'},
  {'bb', 'g', 'k', 'a', 'e'}
};

int keyMapF[NUM_ROWS][NUM_COLS] =
{
  {NOTE_FS6, 'r', NOTE_DS6, NOTE_CS6, 'q'},
  {NOTE_G6, NOTE_F6, NOTE_E6, NOTE_D6, NOTE_C6},
  {NOTE_GS6, NOTE_AS6, 'i', NOTE_CS7, NOTE_DS7},
  {'g', 'e', 'k', 'g', 'a'},
  {NOTE_A6, NOTE_B6, NOTE_C7, NOTE_D7, NOTE_E7},
  {'vv', 'cc', 'xx', 'zz', 'z'},
  {NOTE_CS8, NOTE_DS8, 'k', 'e', 'e'},
  {'bb', 'g', 'k', 'a', 'e'}
};

int debounceCount[NUM_ROWS][NUM_COLS];

// Define the row and column pins

byte colPins[NUM_COLS] = {4, 5, 6, 7, 8};
byte rowPins[NUM_ROWS] = {3, 14, 15, 16, 18, 19, 20, 21};

void controlChange(byte thechannel, byte control, byte value) {
  midiEventPacket_t event = {0x0B, 0xB0 | thechannel, control, value};
  MidiUSB.sendMIDI(event);
  MidiUSB.flush();
}

void setup()
{
  Serial.begin(9600);      // open the serial port at 9600 bps:
  strip.begin();
  strip.show(); // Initialize all pixels to 'off'
  strip.setBrightness(maxBri);
  randomSeed(analogRead(10));

  for (byte c = 0 ; c < NUM_COLS ; c++)
  {
    pinMode(colPins[c], INPUT);
    digitalWrite(colPins[c], HIGH);

    for (byte r = 0 ; r < NUM_ROWS ; r++)
    {
      pinMode(rowPins[r], INPUT);
    }

  }

  pinMode(A10, INPUT_PULLUP);

}

void loop()
{

  for (int a = 0 ; a < 100 ; a++)
  {

    for (byte r = 0 ; r < NUM_ROWS ; r++)
    {
      // Run through the rows, turn them on

      pinMode(rowPins[r], OUTPUT);
      digitalWrite(rowPins[r], LOW);

      for (byte c = 0 ; c < NUM_COLS ; c++)
      {
        if (digitalRead(colPins[c]) == LOW)
        {
          a = 0;
          pressKey(r, c);
        } else {
          midicheck();
          midinote();
        }
      }

      // Turn the row back off
      pinMode(rowPins[r], INPUT);
    }

  }

  lightMove();

}

void midinote() {

  if (midinoteon) {
    if (!midion&&!key) {
      if (vib > 0) {
        tone(9, (pitchFrequency[pitch + midiup * 12]*mpitch) + viblive, susmult / 2);
        delay(dutymult / 3);
      } else {
        tone(9, pitchFrequency[pitch + midiup * 12]*mpitch, susmult / 2);
        delay(dutymult / 3);
      }
    }
    pitcher();
    viber();
    if (freshnote) {
      if (sus != 1) {
        sus = 1;
        susmult = sus * 30;
        dutymult = (duty * ((susmult / 3) * 2)) + (susmult / 3);
      }
      int k = random(0, 4);
      int d = random(0, 3);
      colorMap[d][k] = random(255);
      strip.setPixelColor(4, strip.Color(250 - ((octave - 1) * 40), 50 + (205 - (midion * 205)), (duty) * 50));
      strip.show();
      freshnote = false;
    }
  }
}

void midicheck() {
  midiEventPacket_t rx = MidiUSB.read();
  switch (rx.header) {
    case 0:
      break; //No pending events
    case 0x9:
      midinoteon = true;
      //  rx.byte1 & 0xF,  //channel
      freshnote = true;
      pitch = rx.byte2;        //pitch
      //    rx.byte3         //velocity
      break;
    case 0x8:
      if (rx.byte2 = pitch) {
        midinoteon = false;
        key=0;
      }
      break;
  }
}

void pressKey(byte r, byte c) {

  if (keyMap[r][c] == 'xx') {
    midiup++;
    if (midiup > 4) {
      midiup = 4;
    }
    strip.setPixelColor(4, 0, 128, 0);
    strip.show();
    delay(300);
  }
  else if (keyMap[r][c] == 'zz') {
    midiup--;
    if (midiup < 0) {
      midiup = 0;
    }
    strip.setPixelColor(4, 128, 0, 0);
    strip.show();
    delay(300);
  }
  else if (keyMap[r][c] == 'cc') {
    if (!b3) {
      b3 = true;
      midion = true;
      strip.setPixelColor(4, 128, 0, 0);
    } else {
      b3 = false;
      midion = false;
      strip.setPixelColor(4, 0, 128, 0);
    }
    strip.show();
    delay(300);
  }
  else if (keyMap[r][c] == 'vv') {
    if (pitchoct) {
      pitchoct = false;
          strip.setPixelColor(4, 128, 0, 0);
    } else {
      pitchoct = true;
          strip.setPixelColor(4, 0, 128, 0);
    }
    strip.show();
    delay(300);
  }
  else if (keyMap[r][c] == 'bb') {
    if (!b5) {
      b5 = true;
      controlChange(channel, 74, 127);
      delay(300);
    } else {
      b5 = false;
      controlChange(channel, 74, 0);
      delay(300);
    }
  }
  else  if (keyMap[r][c] == 'z')
  {
    octave = ++octave;
    if (octave > 5) {
      octave = 3;
    }
  }
  else if (keyMap[r][c] == 'a') // vib area ~~~~~~~~~~~~~~~
  {
    vib++;

    if (vib > 4) {
      vib = 0;
    }
    if (vib == 1) {
      vibs = 1;
      vibd = 5;
    }
    else if (vib == 2) {
      vibs = 2;
      vibd = 10;
    }
    else if (vib == 3) {
      vibs = 3;
      vibd = 12;
    }
    else if (vib == 4) {
      vibs = 5;
      vibd = 15;
    }

    strip.setPixelColor(4, 128, 96, 0);
    strip.show();
    delay(100);
    strip.setPixelColor(4, 0, 0, 0);
    strip.show();
    delay(100);
  
  }
  else if (keyMap[r][c] == 'g')
  {
    octave = --octave;
    if (octave < 1) {
      octave = 1;
    }
    viber();
    lightMove();
    delay(300);
  }
  else if (keyMap[r][c] == 'k')
  {
    octave = ++octave;
    if (octave > 6) {
      octave = 6;
    }
    viber();
    lightMove();
    delay(300);
  }

  else if (keyMap[r][c] == 'r')
  {
    sus = ++sus;
    if (sus > 5) {
      sus = 1;
    }
    susmult = sus * 30;
    dutymult = (duty * ((susmult / 3) * 2)) + (susmult / 3);

    delay(300);
  }

  else if (keyMap[r][c] == 'q')
  {
    eff = ++eff;
    if (eff >= 30 ) {
      eff = 0;
      sus = 1;
      susmult = 30;
      duty = 0;
      dutymult = 10;
    } else {
      susmult = eff + 18;
      dutymult = eff + 18;
    }
    delay(60);
  }
  else if (keyMap[r][c] == 'i')
  {
    if (eff > 0) {
      //if we are in eff mode, this button does dark mode
      if (maxBri == 26) {
        maxBri = 255;
      } else {
        maxBri = 26;
      }
      eff = 0;
      sus = 1;
      susmult = 30;
      duty = 0;
      dutymult = 10;
      strip.setBrightness(maxBri);
    } else {
      duty = ++duty;
      if (duty > 4 ) {
        duty = 0;
      }
      dutymult = (duty * ((susmult / 3) * 2)) + (susmult / 3);
    }
    delay(300);
  }

  else if (keyMap[r][c] == 'e') {
    eff = 0;
    sus = 1;
    susmult = 30;
    duty = 0;
    dutymult = 10;
    octave = 5;
    vib = 0;
    vibdown = false;
    vibs = 0;
    vibd = 0;
    viblive = 0;
    midinoteon = false;

    delay(60);
  }
  else
  {

    if (octave == 1) key = keyMap[r][c];
    if (octave == 2) key = keyMapB[r][c];
    if (octave == 3) key = keyMapC[r][c];
    if (octave == 4) key = keyMapD[r][c];
    if (octave == 5) key = keyMapE[r][c];
    if (octave == 6) key = keyMapF[r][c];

    pitcher();
    viber();

    // where the magic happens ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    if (vib > 0) {
      if (key > 0) tone(9, (key * mpitch) + viblive, susmult);
      delay(dutymult);
    }
    else {
      if (key > 0) tone(9, key * mpitch, susmult);
      delay(dutymult);
    }

  }
}

void viber() {
  if (vib > 0) {
    if (vibdown) {
      viblive = viblive - vibs;
      if (viblive < 0 - vibd) {
        vibdown = false;
      }
    } else {
      viblive = viblive + vibs;
      if (viblive > vibd) {
        vibdown = true;
      }
    }
    //  strip.setBrightness((maxBri - 80) + (viblive * 4));
    //  strip.show();
  }
}

void pitcher() {
  double pitchcheck = analogRead(A10);
  if (pitchoct) {
    if (pitchcheck < 750) {
      mpitch = 1 + ((600 - (pitchcheck - 200)) / 600);
    } else {
      mpitch = 1;
    }
    if (mpitch < 1) {
      mpitch = 1;
    }
    if (mpitch > 2) {
      mpitch = 2;
    }
  } else {
    if (pitchcheck < 750) {
      mpitch = 1 + (((600 - (pitchcheck - 150)) / 600) / 8);
    } else {
      mpitch = 1;
    }
    if (mpitch < 1) {
      mpitch = 1;
    }
    if (mpitch > 1.12) {
      mpitch = 1.12;
    }
  }

}

void lightMove() {

  int j = random(0, 4);
  int c = random(0, 3);


  if (random(2) >= 1) {
    colorMap[c][j] = colorMap[c][j] + sus * sus;
    if (colorMap[c][j] >= maxBri) {
      colorMap[c][j] = maxBri - 1;
    }
  } else {
    colorMap[c][j] = colorMap[c][j] - sus * sus;
    if (colorMap[c][j] <= 0) {
      colorMap[c][j] = 1;
    }
  }

  if (eff != 0 ) {
    strip.setPixelColor(random(0, 4), strip.Color(random(1, eff * 7), random(1, eff * 7), random(1, eff * 7)));
    strip.setPixelColor(4, strip.Color(250 - ((octave - 1) * 40), random(1, eff * 7), random(1, eff * 7)));

  } else if (duty != 0) {
    strip.setPixelColor(4, strip.Color(250 - ((octave - 1) * 40), (sus - 1) * 50, (duty) * 50));
  } else {
    strip.setPixelColor(4, strip.Color(250 - ((octave - 1) * 40), (sus - 1) * 50, (duty) * 50));
  }
  strip.setPixelColor(j, strip.Color(colorMap[0][j], colorMap[1][j], colorMap[2][j]));

  strip.show();
}