Digital Electronics Lecture 4

Here is my updated code:

int potValue=0; //variables assigned
int pause=0;
int someVar= 0;
int numLED = 4;

int ledPins[4] = {28,29,30,31};
int buttonPins[4] = {33,34,35,36};

void setup() {
    Serial.begin(9600);
    for(int i=0;i<4;i++){
      pinMode(ledPins[i], OUTPUT);
      pinMode(buttonPins[i], INPUT);
    }
}

void loop(){
  potValue = analogRead(A13);
  pause = potValue;

  numLED= map(analogRead(A21),0,1024, 1,4);

  if(digitalRead(buttonPins[0]) == HIGH) {
    for(int i=0;i<numLED;i++){
      digitalWrite(ledPins[i], HIGH);
    }
    delay(pause);
    for(int i=0;i<numLED;i++){
      digitalWrite(ledPins[i], LOW);
    }
    delay(pause);
  }
  
  if((digitalRead(buttonPins[1]) == HIGH) && (digitalRead(buttonPins[2]) == HIGH)) {
    for(int i=0;i<numLED;i++){
      digitalWrite(ledPins[i], HIGH);
      delay(pause);
      digitalWrite(ledPins[i], LOW);
    }
  }

  if((digitalRead(buttonPins[1]) == HIGH) && (digitalRead(buttonPins[2]) == LOW)) {
    for(int i=numLED;i>0;i--){
      digitalWrite(ledPins[i-1], HIGH);
      delay(pause);
      digitalWrite(ledPins[i-1], LOW);
    }
  }
  
  if(digitalRead(buttonPins[3]) == HIGH){
    someVar = random(28, 32);
    digitalWrite(someVar, HIGH);
    delay(pause);
    digitalWrite(someVar, LOW);
  }
}

Digital Electronics Lab 5

int ledPinArray[3] = {31, 30, 29}; //arrays and variables assigned
int notePotVals[3] = {0, 0, 0};
int mappedNotePotVals[3] = {0, 0, 0};
int toggleSwitch[2] = {15, 14};
int pot[3] = {A13, A15, A16};
int totalPots = 3;
int totalLeds = 3;

int onoff = 38;

int tempo = 0;
int tempoPin = A20;

void setup() {
  for (int i = 0; i < totalLeds; i++) {
    pinMode(ledPinArray[i], OUTPUT);
  }
  Serial.begin(9600);
  pinMode(toggleSwitch[0], INPUT);
  pinMode(toggleSwitch[1], INPUT);
  pinMode(onoff, INPUT);

}

void loop() {
  if (digitalRead(onoff) == HIGH) {
    sequenceforward();
  }
  else if (digitalRead(onoff) == LOW) {
    sequencebackward();
  }

  sequenceforward();
}

void sequenceforward() { //sequence forward
  if (digitalRead(toggleSwitch[1]) == HIGH) {
    tempo = analogRead(tempoPin);

    for (int i = 0; i < totalPots; i++) {
      notePotVals[i] = analogRead(pot[i]);
      mappedNotePotVals[i] = map(notePotVals[i], 0, 1023, 60, 72);
      if (digitalRead(toggleSwitch[0]) == HIGH) {
        mappedNotePotVals[i] = mappedNotePotVals[i] + 12;
      }

      usbMIDI.sendNoteOn(mappedNotePotVals[i], 127, 1);
      digitalWrite(ledPinArray[i], HIGH);
      delay(tempo);
      usbMIDI.sendNoteOff(mappedNotePotVals[i], 0, 1);
      digitalWrite(ledPinArray[i], LOW);
    }
  }
}

void sequencebackward() {
  if (digitalRead(toggleSwitch[1]) == HIGH) {
    tempo = analogRead(tempoPin);

    for (int i = totalPots - 1; i >= 0; i--) {
      notePotVals[i] = analogRead(pot[i]);
      mappedNotePotVals[i] = map(notePotVals[i], 0, 1023, 60, 72);
      if (digitalRead(toggleSwitch[0]) == HIGH) {
        mappedNotePotVals[i] = mappedNotePotVals[i] + 12;
      }

      usbMIDI.sendNoteOn(mappedNotePotVals[i], 127, 1);
      digitalWrite(ledPinArray[i], HIGH);
      delay(tempo);
      usbMIDI.sendNoteOff(mappedNotePotVals[i], 0, 1);
      digitalWrite(ledPinArray[i], LOW);
    }
  }
}

Digital Electronics Lecture Assign 3

Digital Electronics Lecture 3

PART 1: This midi keyboard is different from the previous ones we have done. In this keyboard there is no delay when a button is pressed and when a sound is heard. This midi keyboard also has a variable sustain. I accomplished this using if statements that check for the exact moment a button is pressed and released to send MIDI information. This works more precisely, rather than using the send midi function off after the delay.

int ledPin1 = 28; //setting pins and variable names
int ledPin2 = 29;
int ledPin3 = 30;
int ledPin4 = 31;
int buttonPin1 = 33;
int buttonPin2 = 34;
int buttonPin3 = 35;
int buttonPin4 = 36;
bool buttonPress1= LOW; //boolian 
bool lastButtonPress1= LOW;
bool buttonPress2= LOW;
bool lastButtonPress2= LOW;
bool buttonPress3= LOW;
bool lastButtonPress3= LOW;
bool buttonPress4= LOW;
bool lastButtonPress4= LOW;

void setup() {
    Serial.begin(9600);

    pinMode(ledPin1, OUTPUT); //pin mode
    pinMode(ledPin2, OUTPUT);
    pinMode(ledPin3, OUTPUT);
    pinMode(ledPin4, OUTPUT);

    pinMode(buttonPin1, INPUT);
    pinMode(buttonPin2, INPUT);
    pinMode(buttonPin3, INPUT);
    pinMode(buttonPin4, INPUT);

}

void loop() { //checkbutton function
  checkButton();

}

void checkButton(){
  checkButton1();
  checkButton2();
  checkButton3();
  checkButton4();
  
}

void checkButton1(){ //checkbutton function for each button
  lastButtonPress1=buttonPress1;
  buttonPress1=digitalRead(buttonPin1);
  if( (buttonPress1 == HIGH) and (lastButtonPress1 == LOW)){
    usbMIDI.sendNoteOn(60, 90, 1);
    digitalWrite(ledPin1, HIGH);
    delay(5); //setting the delay to 5
  } else if (lastButtonPress1 == HIGH and buttonPress1== LOW){
    usbMIDI.sendNoteOff(60, 0, 1);
    digitalWrite(ledPin1, LOW);
    delay(5);
  }
}

void checkButton2(){
  lastButtonPress2=buttonPress2;
  buttonPress2=digitalRead(buttonPin2);
  if( (buttonPress2 == HIGH) and (lastButtonPress2 == LOW)){
    usbMIDI.sendNoteOn(64, 90, 1);
    digitalWrite(ledPin2, HIGH);
    delay(5);
  } else if (lastButtonPress2 == HIGH and buttonPress2== LOW){
    usbMIDI.sendNoteOff(64, 0, 1);
    digitalWrite(ledPin2, LOW);
    delay(5);
  }
}

void checkButton3(){
  lastButtonPress3=buttonPress3;
  buttonPress3=digitalRead(buttonPin3);
  if( (buttonPress3 == HIGH) and (lastButtonPress3 == LOW)){
    usbMIDI.sendNoteOn(67, 90, 1);
    digitalWrite(ledPin3, HIGH);
    delay(5);
  } else if (lastButtonPress3 == HIGH and buttonPress3 == LOW){
    usbMIDI.sendNoteOff(67, 0, 1);
    digitalWrite(ledPin3, LOW);
    delay(5);
  }
}

PART 2: Potentiometer demo

int potVal = 0; //setting up variables and starting values
int lastPotVal = 0;

void setup() { //serial begin
  Serial.begin(9600);
}

void loop() { //loop using the map function.
  lastPotVal = potVal;
  potVal = map(analogRead(A13), 0 , 1023, 0, 10);
  if(potVal != lastPotVal) {
    Serial.println(potVal); //prints value in serial monitor
    delay(10);
  }
}

Digital Lecture Lab 4

int redLED = 10;
int yellowLED = 24;
int blueLED = 26;

int toggle = 39;
int onoff = 23;
int pot1 = 0;
int pot2 = 0;
int pot3 = 0;
int tempoPot = 0;
int mappedPot1 = 0;
int mappedPot2 = 0;
int mappedPot3 = 0;
int mappedtempoPot = 0;

void setup() {
  pinMode(redLED, OUTPUT);
  pinMode(yellowLED, OUTPUT);
  pinMode(blueLED, OUTPUT);
  Serial.begin(9600);

  pinMode(toggle, INPUT);
  pinMode(onoff, INPUT);
}

void loop() {
  
  if(digitalRead(onoff) == HIGH) {
    pot1 = analogRead(A13);
    pot2 = analogRead(A15);
    pot3 = analogRead(A16);
    tempoPot = analogRead(A14);
    mappedPot1 = map(pot1, 0, 1023, 60, 72);
    mappedPot2 = map(pot2, 0, 1023, 64, 76);
    mappedPot3 = map(pot3, 0, 1023, 67, 79);
    mappedtempoPot = map(tempoPot, 0, 1023, 100, 1000);


    if(digitalRead(toggle) == HIGH) {
      pot1 = mappedPot1 + 12;
      pot2 = mappedPot2 + 12;
      pot3 = mappedPot3 + 12;
    }

    if(digitalRead(toggle) == LOW) {
      pot1 = mappedPot1;
      pot2 = mappedPot2;
      pot3 = mappedPot3;
    }

    usbMIDI.sendNoteOn(pot1, 127, 1);
    digitalWrite(redLED, HIGH);
    delay(mappedtempoPot);
    usbMIDI.sendNoteOff(pot1, 0, 1);
    digitalWrite(redLED, LOW);
  
  
    usbMIDI.sendNoteOn(pot2, 127, 1);
    digitalWrite(yellowLED, HIGH);
    delay(mappedtempoPot);
    usbMIDI.sendNoteOff(pot2, 0, 1);
    digitalWrite(yellowLED, LOW);
  
  
    usbMIDI.sendNoteOn(pot3, 127, 1);
    digitalWrite(blueLED, HIGH);
    delay(mappedtempoPot);
    usbMIDI.sendNoteOff(pot3, 0, 1);
    digitalWrite(blueLED, LOW);
    }
  }



  

Digital Lecture Assignment 2

Digital Lecture Assignment 2

Part 1) Fix this broken circuit:

Link to working Tinkercad circuit: https://www.tinkercad.com/things/kYpvV1CcXu9

Part 2) Explain this code in English:

Function1() basically makes each LED blink. But when all switches are open, the LEDs will blink down the chain from left to right with 500milliseonds between each blink. Function2() basically makes it so that when one LED is on and blinking, no other LED in the circuit can be on. Finally, Function3() makes each LED(that is active) blink at the same time will 500milliseconds inbetween.

Part 3) Simplify the code from Part 2 as much as possible:
Link to working Tinkercad circuit: https://www.tinkercad.com/things/626pyXzyVvq

Digital Electronics Lab 3

USB MIDI Lab:

My Code:

int redLED = 10;
int yellowLED = 24;
int blueLED = 26;
int greenLED = 28;

int buttonPin1 = 36;
int buttonPin2 = 35;
int buttonPin3 = 33;
int buttonPin4 = 32;
int toggle = 29;
int potValue = 0;

void setup() {
  pinMode(redLED, OUTPUT);
  pinMode(yellowLED, OUTPUT);
  pinMode(blueLED, OUTPUT);
  pinMode(greenLED, OUTPUT);

  pinMode(buttonPin1, INPUT);
  pinMode(buttonPin2, INPUT);
  pinMode(buttonPin3, INPUT);
  pinMode(buttonPin4, INPUT);
  pinMode(toggle, INPUT);
}



void loop() {
  toggleMode();
}


void keyboardMode() {
  checkButton(buttonPin1, redLED, 60);
  checkButton(buttonPin2, yellowLED, 64);
  checkButton(buttonPin3, blueLED, 67);
  checkButton(buttonPin4, greenLED, 71);
}

void arpeggiatorMode() {
  if (digitalRead(buttonPin1) == HIGH) {
    arpeggio(60);
  }
  if (digitalRead(buttonPin2) == HIGH) {
    arpeggio(64);
  }
  if (digitalRead(buttonPin3) == HIGH) {
    arpeggio(67);
  }
  if (digitalRead(buttonPin4) == HIGH) {
    arpeggio(71);
  }
}

void toggleMode() {
  if (digitalRead(toggle) == LOW) {
    arpeggiatorMode();
  }
  if (digitalRead(toggle) == HIGH) {
    keyboardMode();
  }
}

void arpeggio(int note) {
  potValue = analogRead(A19); //variable for the analog input pin of potentiometer
  usbMIDI.sendNoteOn(note, 127, 1);
  digitalWrite(redLED, HIGH);
  delay(potValue);
  usbMIDI.sendNoteOff(note, 0, 1);
  digitalWrite(redLED, LOW);
  usbMIDI.sendNoteOn(note + 4, 127, 1);
  digitalWrite(yellowLED, HIGH);
  delay(potValue);
  usbMIDI.sendNoteOff(note + 4, 0, 1);
  digitalWrite(yellowLED, LOW);
  usbMIDI.sendNoteOn(note + 7, 127, 1);
  digitalWrite(blueLED, HIGH);
  delay(potValue);
  usbMIDI.sendNoteOff(note + 7, 0, 1);
  digitalWrite(blueLED, LOW);
  usbMIDI.sendNoteOn(note + 11, 127, 1);
  digitalWrite(greenLED, HIGH);
  delay(potValue);
  usbMIDI.sendNoteOff(note + 11, 0, 1);
  digitalWrite(greenLED, LOW);
}

void checkButton(int buttonPin, int ledPin, int note) {
  if (digitalRead(buttonPin) == HIGH) {
    digitalWrite(ledPin, HIGH);
    usbMIDI.sendNoteOn(note, 127, 1);
    delay(500);
    digitalWrite(ledPin, LOW);
    usbMIDI.sendNoteOff(note, 0, 1);
  }


}

Digital Electronics Lab 2

Part 1)

Part 2)

Part 3)

Part 4)

Part 5)

Part 6)

int redLED = 10;
int greenLED = 24;
int yellow1LED = 11;
int yellow2LED = 25;
int buttonPin = 36;
int buttonPin2 = 34;
int potValue = 0;
int toggle = 38;

void setup() {
  pinMode(redLED, OUTPUT);
  pinMode(yellow1LED, OUTPUT);
  pinMode(greenLED, OUTPUT);
  pinMode(yellow2LED, OUTPUT);
  pinMode(buttonPin, INPUT);
  pinMode(buttonPin2, INPUT);
}

void loop() {
  potValue = analogRead(A13); //variable for input pin of button 1
  if (digitalRead(buttonPin) == HIGH) {
    digitalWrite(redLED, HIGH);
    digitalWrite(yellow1LED, HIGH);
    digitalWrite(greenLED, HIGH);
    digitalWrite(yellow2LED, HIGH);
    delay(potValue);
    digitalWrite(redLED, LOW);
    digitalWrite(yellow1LED, LOW);
    digitalWrite(greenLED, LOW);
    digitalWrite(yellow2LED, LOW);
    delay(potValue);
  } 
 if (digitalRead(toggle) == LOW) {
  if (digitalRead(buttonPin2) == HIGH) {
    digitalWrite(redLED, HIGH);
    delay(potValue);
    digitalWrite(redLED, LOW);
    digitalWrite(yellow1LED, HIGH);
    delay(potValue);
    digitalWrite(yellow1LED, LOW);
    digitalWrite(greenLED, HIGH);
    delay(potValue);
    digitalWrite(greenLED, LOW);
    digitalWrite(yellow2LED, HIGH);
    delay(potValue);
    digitalWrite(yellow2LED, LOW);
  }
 else {
   if (digitalRead(buttonPin2) == HIGH) {
    digitalWrite(yellow2LED, HIGH);
    delay(potValue);
    digitalWrite(yellow2LED, LOW);
    digitalWrite(greenLED, HIGH);
    delay(potValue);
    digitalWrite(greenLED, LOW);
    digitalWrite(yellow1LED, HIGH);
    delay(potValue);
    digitalWrite(yellow1LED, LOW);
    digitalWrite(redLED, HIGH);
    delay(potValue);
    digitalWrite(redLED, LOW);
    
  }
}}}

FALL 2020 DIGITAL LECTURE ASSIGNMENT 1

Fall 2020 Digital Lecture Assignment 1

My Tinkercad circuit: 

https://www.tinkercad.com/things/jqg6hZ0D9r7

My changes to the original circuit, are detailed below:

  1. Added a white LED.
  2. The white LED is only active when the button is pressed. 
  3. Added 2 red LEDs that are active when the green and blue LEDs are.
  4. Changed the pin assigned to the button from 10 to 5.
  5. Changed the millisecond blink rate on the green, blue and red LEDs.

Digital Electronics Lab 1

Digital Electronics Lab 1

  1. Arduino/Teensy (I have ordered the parts but have not received them yet.)
  1. Research

Find 5 Arduino projects online that are interesting to you and link to them, with a one paragraph description of what each one is.

1. https://www.instructables.com/id/Simple-Electronic-Piano/

This project is a relatively simple piano made with a battery, pushbuttons, a timer, a 100 nF capacitor, an assortment of resistors and some wire. This is effectively a microcontroller, that plays a given pitch class assigned to buttons, which will play a scale from c5 to c6. I am not entirely sure how the resistors determine what pitch is played, but the layout is 8 buttons across the breadboard, each  meant to represent a key in a 8 note scale.

2.https://create.arduino.cc/projecthub/razhaleva/arpeggino-midi-arpeggiator-sequencer-recorder-and-looper-5aeb7b?ref=tag&ref_id=music&offset=1

This project is an all in one midi sequencer/arpeggiator that lets you record multiple sequences. You can delete recorded layers, record new ones on top of the sequence, and even reconfigure the recorded layers. This sequencer is effectively a midi sequencer made up of buttons, an arduino, an alphanumeric LCD, and an Analogue/Digital MUX Breakout. This is an interesting project because having a midi sequencer of any kind seems like a useful tool.

3.https://create.arduino.cc/projecthub/deltakilo/vu-meter-for-audio-signal-dbu-using-lcd-0cef6d?ref=tag&ref_id=audio&offset=5

This project is a VU meter for Audio Signal (measured in dBu). This project was made using a DFRobot 12C 16×2 Arduino LCD display module, jumper wires, a 100nF capacitor, a through hole resistor, a couple of generic resistors, and an arduino. This project has a cool aethstetic, and it seems relatively straightforward once you acquire the required parts. This project interests me because the screen could be used for anything.

4.https://create.arduino.cc/projecthub/ashraf_minhaj/tuneglass-can-we-make-music-using-our-eyes-29ea91?ref=tag&ref_id=audio&offset=112

This project is a pair of sunglasses that generates tones using the wearer’s eyes. To make this project, its creator used the following: Both a arduino pro, and a UNO arduino. A speaker, an IR sensor, UT source electronic parts, and a 0.25 W 8ohms speaker. The entire concept of this project interests me because I am interested in wearable speakers/music technology. 

5.https://create.arduino.cc/projecthub/anewxptr/crossfader-with-arduino-for-virtualdj-c6eb43?ref=tag&ref_id=audio&offset=126

This project is a crossfader that works with any DJ software that reads MIDI, using arduino. This project is less conventional than the other ones on my list as it does not require a breadboard or a traditional circuit setup. This project is interesting because of the code that makes the crossfader work with DJ softwares, which is all thanks to the arduino. 

Find 5 of the given projects that are interesting and write a paragraph about each one.

1. Nick Royall’s project is an 8-step, 4-channel audio and MIDI step sequencer and keyboard. Basically, an all-in-one drum machine and keyboard. This project is based around a teensy 3.5, the analogue components only tell the teensy what to do. The synthesizer on this keyboard has four waveforms to choose from (sine, square, triangle, and sawtooth), and the pitch of the waveform is controlled on each step individually by the potentiometer for that step. The drum machine has a few imported drum samples that cannot be changed by the user, but a majority of the drum samples can be changed via C++.

2. Max Chidzero’s project is a teensy based “e-Cajon”. The e-Cajon is composed of two circuits and can be used to trigger on-board drum samples or set to midi mode to act as a midi controller. The Cajon itself was built using the Meinl Percussion MYO-CAJ Build your Own Cajon kit which can be purchased online. According to the demo, using a pair of sticks or hitting the target areas on the Cajon with your fist are the best ways to use the e-Cajon. 

3. Sam Kingston’s project is a 64 LED cube that acts as an audio visualizer. This LED cube is powered by an Arduino Nano microcontroller, which is being sent data from a Teensy. The Teensy takes audio in from any device through a regular 3.5mm jack, and then the code stored within the Teensy separates the audio into 40 frequency bands, then averages them into 8 to correspond with each column on the cube. This project is very interesting, but looks painstakingly annoying to build the LED cube.

4. Matthew Lau made a midi drum pad with 4 separate pads. The pad is designed to trigger four different sounds from the computer. When you hit one of the pads, a contact sensor picks up the vibration and sends a message to the microcontroller. The microcontroller then interprets this message and communicates with any program the user would like, sending a MIDI note which can be used to trigger a sample. 

5. Kelly Dicicco’s final project is a light instrument/synth. Kelly’s project was made of 8 LEDs each opposite a light sensor. There are two main programs to the project: the Arduino code and Max/MSP. The Arduino code has all the directions for the project, telling it what to do, and Max/MSP basically reads in what you’re doing on the hardware and actually plays the note. The code tells the project to play a certain note when each beam of light is broken. 

  1. Brainstorm

Diagram:

  1. Organize parts (done)

Lab 13

Analogue Electronics Lab 13

1. Nick Royall made a 8-step, 4-channel audio and MIDI step sequencer and keyboard. This project looks absolutely sick, but a little complex. The “all-in-one” concept is cool but a little cluttered, I like work with individual insturments with their own functions when producing. I would love to have an attempt at the Midi sequencer/ drum machine that nick made, and maybe add a 3d printed cover. Nick also included an 808 kick, a snare, and a hi-hat, if I was to focus on the drum kit, I would expand the sounds used to a snare, perc, and of course cowbell.

Paul Odenwadlt made a device that allows you to control a granular synthesizer with a Gamecube controller. This is another project that I am interested in, as it looks like more fun to use than it is to code. Paul does say that using a gamecube for anything else but gaming is a difficult task, so maybe using a different type of controller that can be mapped/rewired would be interesting. 

Jordana Bombi made a motion-based controller which allows the user to change values in a computer without using the mouse. This is really cool, I would love make a project similar to this gloves and all. Since in technical terms Jordana’s project converts the given analog values into MIDI values, this could circuit could be used to make an entire suit that can control an array of functions.

2. The digital/microcontroller platform we’ll be using in Digital is called Arduino. It has been around for about 15 years, it is hugely popular, and people have used it to make seemingly any gadget you could ever think of.  Google “Arduino” plus literally any concepts or things you are interested in. Find one project that is music or audio related, and one that isn’t, and link to them and write a little bit about each one.

The first project that caught my eye is related to music, and is made by Shajeeb. Shajeeb made a 32-Band Audio Spectrum Visualizer Analyzer. I found this project on the arduino projects website, and the project consists of 13 total components and a basic understanding of electronics components (which I now have), including the arduino kit. https://create.arduino.cc/projecthub/Shajeeb/32-band-audio-spectrum-visualizer-analyzer-902f51

The second project that caught my eye is not music related, and was made by Teenenggr. Teenenggr made a modern typewriter (which I guess is kind of pointless), using some python code and linear solenoid’s to mimic the sound of a type writer when a key on the keyboard is pressed. I also found this project on the arduino projects website.

3. In digital electronics terms a switch or button is a digital input, an LED is a digital output, and a potentiometer is a digital input.4. I took intro to computer programming first semester, and unfortunatley failed. I was not very good with Python, but I hope that I can do some crash courses over the summer to get familiar with arduino.

Design a site like this with WordPress.com
Get started