Digital Electronics Lab #3

Completed Circuit Demo Video:

Completed Code:

int blueLed = 7;                            // make variable for each of the components on the breadboard
int greenLed = 8;
int whiteLed = 9;
int yellowLed = 10;
int buttonPin1 = 33;
int buttonPin2 = 34;
int buttonPin3 = 35;
int buttonPin4 = 36;
int potValue = 0;
int slideSwitch = 32;
void setup() {

  pinMode(blueLed, OUTPUT);                 // set pinMode for the digital inputs
  pinMode(greenLed, OUTPUT);
  pinMode(whiteLed, OUTPUT);
  pinMode(yellowLed, OUTPUT);
  pinMode(buttonPin1, INPUT);
  pinMode(buttonPin2, INPUT);
  pinMode(buttonPin3, INPUT);
  pinMode(buttonPin4, INPUT);
  pinMode(slideSwitch, INPUT);
}

void loop() {

  if (digitalRead(slideSwitch) == HIGH) {    //keyboard setting
    keyboardMode();
  }

  if (digitalRead(slideSwitch) == LOW) {    //arpeggio setting
    arpeggioMode();
  }
}

void checkButton1() {                       // checkbutton1 function
  if (digitalRead(buttonPin1) == HIGH) {
    usbMIDI.sendNoteOn(60, 127, 1);
    digitalWrite(blueLed, HIGH);
    delay(500);
    usbMIDI.sendNoteOff(60, 0, 1);
    digitalWrite(blueLed, LOW);
    delay(500);
  }
}
void checkButton2() {                       // checkbutton2 function
  if (digitalRead(buttonPin2) == HIGH) {
    usbMIDI.sendNoteOn(64, 127, 1);
    digitalWrite(greenLed, HIGH);
    delay(500);
    usbMIDI.sendNoteOff(64, 0, 1);
    digitalWrite(greenLed, LOW);
    delay(500);
  }
}
void checkButton3() {                       // checkbutton3 function
if (digitalRead(buttonPin3) == HIGH) {
  usbMIDI.sendNoteOn(67, 127, 1);
  digitalWrite(whiteLed, HIGH);
  delay(500);
  usbMIDI.sendNoteOff(67, 0, 1);
  digitalWrite(whiteLed, LOW);
  delay(500);
}
}
void checkButton4() {                       // checkbutton4 function
  if (digitalRead(buttonPin4) == HIGH) {
    usbMIDI.sendNoteOn(71, 127, 1);
    digitalWrite(yellowLed, HIGH);
    delay(500);
    usbMIDI.sendNoteOff(71, 0, 1);
    digitalWrite(yellowLed, LOW);
    delay(500);
  }
}

void keyboardMode() {                      //keyboardMode function
  checkButton1();
  checkButton2();
  checkButton3();
  checkButton4();
}

void arpeggio(int note) {                   // arpeggio function
  potValue = analogRead(A18);
  usbMIDI.sendNoteOn(note, 127, 1);
  delay(potValue);
  usbMIDI.sendNoteOff(note, 0, 1);

  usbMIDI.sendNoteOn(note + 4, 127, 1);
  delay(potValue);
  usbMIDI.sendNoteOff(note + 4, 0, 1);

  usbMIDI.sendNoteOn(note + 7, 127, 1);
  delay(potValue);
  usbMIDI.sendNoteOff(note + 7, 0, 1);

  usbMIDI.sendNoteOn(note + 11, 127, 1);
  delay(potValue);
  usbMIDI.sendNoteOff(note + 11, 0, 1);
}


void arpeggioMode() {                         //arpeggioMode function
  if (digitalRead(buttonPin1) == HIGH) {
    arpeggio(60);
  }

  if (digitalRead(buttonPin2) == HIGH) {
    arpeggio(64);
  }

  if (digitalRead(buttonPin3) == HIGH) {
    arpeggio(67);
  }

  if (digitalRead(buttonPin4) == HIGH) {
    arpeggio(71);
  }




}

Demo Song:

I decided I would try out the MIDI controller and try to make a quick song idea! Here’s what I came up with:

Extra Credit:

This took me forever, so I hope it’s right!

Extra Credit Code:




int blueLed = 7;                            // make variable for each of the components on the breadboard
int greenLed = 8;
int whiteLed = 9;
int yellowLed = 10;
int buttonPin1 = 33;
int buttonPin2 = 34;
int buttonPin3 = 35;
int buttonPin4 = 36;
int potValue = 0;
int slideSwitch = 32;
int slideSwitch2 = 31;
void setup() {

  pinMode(blueLed, OUTPUT);                 // set pinMode for the digital inputs
  pinMode(greenLed, OUTPUT);
  pinMode(whiteLed, OUTPUT);
  pinMode(yellowLed, OUTPUT);
  pinMode(buttonPin1, INPUT);
  pinMode(buttonPin2, INPUT);
  pinMode(buttonPin3, INPUT);
  pinMode(buttonPin4, INPUT);
  pinMode(slideSwitch, INPUT);
  pinMode(slideSwitch2, INPUT);
}

void loop() {

  if (digitalRead(slideSwitch) == HIGH) {    //keyboard setting
    keyboardMode();
  }

  if (digitalRead(slideSwitch) == LOW) {    //arpeggio setting
    arpeggioMode();
  }
}

void checkButton1() {                                                         // checkbutton1 function
  if (digitalRead(buttonPin1) == HIGH and digitalRead(slideSwitch2) == LOW) {
    usbMIDI.sendNoteOn(60, 127, 1);
    digitalWrite(blueLed, HIGH);
    delay(500);
    usbMIDI.sendNoteOff(60, 0, 1);
    digitalWrite(blueLed, LOW);
    delay(500);
  }
  if (digitalRead(buttonPin1) == HIGH and digitalRead(slideSwitch2) == HIGH) {
    usbMIDI.sendNoteOn(72, 127, 1);
    digitalWrite(blueLed, HIGH);
    delay(500);
    usbMIDI.sendNoteOff(76, 0, 1);
    digitalWrite(blueLed, LOW);
    delay(500);
  }
}

void checkButton2() {                                                           // checkbutton2 function
  if (digitalRead(buttonPin2) == HIGH and digitalRead(slideSwitch2) == LOW) {
    usbMIDI.sendNoteOn(64, 127, 1);
    digitalWrite(greenLed, HIGH);
    delay(500);
    usbMIDI.sendNoteOff(64, 0, 1);
    digitalWrite(greenLed, LOW);
    delay(500);
  }
  if (digitalRead(buttonPin2) == HIGH and digitalRead(slideSwitch2) == HIGH) {
    usbMIDI.sendNoteOn(76, 127, 1);
    digitalWrite(greenLed, HIGH);
    delay(500);
    usbMIDI.sendNoteOff(76, 0, 1);
    digitalWrite(greenLed, LOW);
    delay(500);
  }
}

void checkButton3() {                                                          // checkbutton3 function
  if (digitalRead(buttonPin3) == HIGH and digitalRead(slideSwitch2) == LOW) {
    usbMIDI.sendNoteOn(67, 127, 1);
    digitalWrite(whiteLed, HIGH);
    delay(500);
    usbMIDI.sendNoteOff(67, 0, 1);
    digitalWrite(whiteLed, LOW);
    delay(500);
  }
  if (digitalRead(buttonPin3) == HIGH and digitalRead(slideSwitch2) == HIGH) {
    usbMIDI.sendNoteOn(79, 127, 1);
    digitalWrite(whiteLed, HIGH);
    delay(500);
    usbMIDI.sendNoteOff(79, 0, 1);
    digitalWrite(whiteLed, LOW);
    delay(500);
  }
}

void checkButton4() {                                                               // checkbutton4 function
  if (digitalRead(buttonPin4) == HIGH and digitalRead(slideSwitch2) == LOW) {
    usbMIDI.sendNoteOn(71, 127, 1);
    digitalWrite(yellowLed, HIGH);
    delay(500);
    usbMIDI.sendNoteOff(71, 0, 1);
    digitalWrite(yellowLed, LOW);
    delay(500);
  }
  if (digitalRead(buttonPin4) == HIGH and digitalRead(slideSwitch2) == HIGH) {
    usbMIDI.sendNoteOn(83, 127, 1);
    digitalWrite(yellowLed, HIGH);
    delay(500);
    usbMIDI.sendNoteOff(83, 0, 1);
    digitalWrite(yellowLed, LOW);
    delay(500);
  }
}



void keyboardMode() {                      //keyboardMode function
  checkButton1();
  checkButton2();
  checkButton3();
  checkButton4();
}

void arpeggio(int note) {                   // arpeggio function
  potValue = analogRead(A18);
  usbMIDI.sendNoteOn(note, 127, 1);
  delay(potValue);
  usbMIDI.sendNoteOff(note, 0, 1);

  usbMIDI.sendNoteOn(note + 4, 127, 1);
  delay(potValue);
  usbMIDI.sendNoteOff(note + 4, 0, 1);

  usbMIDI.sendNoteOn(note + 7, 127, 1);
  delay(potValue);
  usbMIDI.sendNoteOff(note + 7, 0, 1);

  usbMIDI.sendNoteOn(note + 11, 127, 1);
  delay(potValue);
  usbMIDI.sendNoteOff(note + 11, 0, 1);
}


void arpeggioMode() {                         //arpeggioMode function
  if (digitalRead(buttonPin1) == HIGH and digitalRead(slideSwitch2) == LOW) {
    arpeggio(60);
  }

  if (digitalRead(buttonPin1) == HIGH and digitalRead(slideSwitch2) == HIGH) {
    arpeggio(72);
  }

  if (digitalRead(buttonPin2) == HIGH and digitalRead(slideSwitch2) == LOW) {
    arpeggio(64);
  }

  if (digitalRead(buttonPin2) == HIGH and digitalRead(slideSwitch2) == HIGH) {
    arpeggio(76);
  }

  if (digitalRead(buttonPin3) == HIGH and digitalRead(slideSwitch2) == LOW) {
    arpeggio(67);
  }

  if (digitalRead(buttonPin3) == HIGH and digitalRead(slideSwitch2) == HIGH) {
    arpeggio(79);
  }

  if (digitalRead(buttonPin4) == HIGH and digitalRead(slideSwitch2) == LOW) {
    arpeggio(71);
  }

  if (digitalRead(buttonPin4) == HIGH and digitalRead(slideSwitch2) == HIGH) {
    arpeggio(83);
  }





}

Leave a comment

Design a site like this with WordPress.com
Get started