Hit the Drums

I had heard that piano was a popular choice in previous years so this week, Suman and I decided to make drums. We used two different rhythms, one for a buzzer and one for the drums, and had them playing at several times as though to be responding to each other, sort of like a drum solo. while the buzzer rhythm is the same one and loops. There is two rhythms for the drums and with each round of the buzzer one of the rhythms plays, alternating. And the servo stands act like hands, playing the drums.

materials:

-2 servos

-1 buzzer

-some wood

-foam board

-tape

Our source for the drums: https://www.instructables.com/id/Simple-Arduino-Drum-Robot/

#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

#include <Servo.h>
#include "pitches.h"

// notes in the melody:
int melody[] = {
  NOTE_C4, NOTE_G3, NOTE_G3, NOTE_A3, NOTE_G3, 0, NOTE_B3, NOTE_C4
};

// note durations: 4 = quarter note, 8 = eighth note, etc.:
int noteDurations[] = {
  4, 8, 8, 4, 4, 4, 4, 4
};

Servo servoL;
Servo servoR;

int BUZZER = 8;

//hardware and pins
int srvoR = 5; //assign digital pwm pin for Left servo
int srvoL = 6; //assign digital pwm pin for Right servo

//musical things
int bpm = 90; //beats per minute
int timeSig = 4; //regular time signature (beats per measure)
int Tbeat = 60000/bpm; //time per beat in milliseconds is one minute divided by beats per minute
int beat = 1; //start the fist measure with the first beat
int measure = 1; //start with the first measure
//servo control
int travel = 17; //in degrees, how far does the servo need to turn
int Tservo = 130; //time allowed for servo to reach position before further instruction in milliseconds

void setup() {

  Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
  //setup code here, to run once:
  //establish each pin mode
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  
  //setup the servos at set at zero
  servoL.attach(srvoL);
  servoR.attach(srvoR);
  servoL.write(0);
  servoR.write(0);
}

void beatTEST(){
  servoR.write(travel);
  servoL.write(travel);
  delay(60000/bpm);
  servoR.write(0);
  servoL.write(0);
  delay(60000/bpm);
}

void quarterBeatL(){
  servoL.write(travel);
  delay(Tservo);
  servoL.write(0);
  delay((60000/bpm)-Tservo);
}

void quarterBeatR(){
  servoR.write(travel);
  delay(Tservo);
  servoR.write(0);
  delay((60000/bpm)-Tservo);
}

void eighthBeatL(){
  servoL.write(travel);
  delay(Tservo);
  servoL.write(0);
  delay((30000/bpm)-Tservo);
}

void eighthBeatR(){
  servoR.write(travel);
  delay(Tservo);
  servoR.write(0);
  delay((30000/bpm)-Tservo);
}

void loop() {

   for (int thisNote = 0; thisNote < 8; thisNote++) {

    // to calculate the note duration, take one second divided by the note type.
    //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
    int noteDuration = 1000 / noteDurations[thisNote];
    tone(8, melody[thisNote], noteDuration);

    // to distinguish the notes, set a minimum time between them.
    // the note's duration + 30% seems to work well:
    int pauseBetweenNotes = noteDuration * 1.30;
    delay(pauseBetweenNotes);
    // stop the tone playing:
    noTone(8);
    
  }
  delay(50);
  if(measure == 1){ //a set of four quarter notes. 
    quarterBeatR();
    quarterBeatL();
    quarterBeatR();
    quarterBeatL();
    measure = 2;
  }

   for (int thisNote = 0; thisNote < 8; thisNote++) {

    // to calculate the note duration, take one second divided by the note type.
    //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
    int noteDuration = 1000 / noteDurations[thisNote];
    tone(8, melody[thisNote], noteDuration);

    // to distinguish the notes, set a minimum time between them.
    // the note's duration + 30% seems to work well:
    int pauseBetweenNotes = noteDuration * 1.30;
    delay(pauseBetweenNotes);
    // stop the tone playing:
    noTone(8);
    
  }
  delay(50);
  if(measure == 2){ //a set of 8 eighth notes.  not perfectly in time because the motors are slow
    eighthBeatR();
    eighthBeatL();
    eighthBeatR();
    eighthBeatL();
    eighthBeatR();
    eighthBeatL();
    eighthBeatR();
    eighthBeatL();
    measure = 1;
  }
}

 

Group Project – Music Box

Our task this week was to work with one other person from class and make a musical instrument. Sara and I decided to make a music box.

The materials we used on our Arduino are as follows:

  • two servo motors (one for the rotating figurine, one for the lid opener)
  • one buzzer (for tone)
  • a potentiometer (to switch the music box on)
  • a wooden box
  • a small figurine

First, we stuck the servo boxes using velcro into the box, and then we added the buzzer. One servo was to just open the box and the other one was to turn the figurine around.

The building process: 

Our Code:

#include <Servo.h>
 
Servo servo;
Servo servo2;

//PINS
int speakerPin = 8;
int servoPin = 10;
int servo2Pin = 9;
int potentioPin = A2;
int length = 15; // the number of notes
char notes[] = "ccggaagffeeddc "; // a space represents a rest
int beats[] = { 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 2, 4 };
int tempo = 300;



//FOR SERVO
const int MAX_DISTANCE = 160;
//const int MED_DISTANCE = 90;
const int MIN_DISTANCE = 20;
int degree = 10;
int pos = 50;
int pos2;

//FOR POTENTIOMETER
int potentioValue = 0;

int i = 0;

void setup() {
  Serial.begin(9600);
  servo.attach(servoPin);
  servo2.attach(servo2Pin);
  pinMode(speakerPin, OUTPUT);
  servo2.write(20);
  servo.write(20);
}

void playTone(int tone, int duration) {
  for (long i = 0; i < duration * 1000L; i += tone * 2) {
    digitalWrite(speakerPin, HIGH);
    delayMicroseconds(tone);
    digitalWrite(speakerPin, LOW);
    delayMicroseconds(tone);
  }
}

void playNote(char note, int duration) {
  char names[] = { 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C' };
  int tones[] = { 1915, 1700, 1519, 1432, 1275, 1136, 1014, 956 };

  // play the tone corresponding to the note name
  for (int i = 0; i < 8; i++) {
    if (names[i] == note) {
      playTone(tones[i], duration);
    }
  } 

   pinMode(speakerPin, OUTPUT);
}
 
void loop() {

  potentioValue = analogRead(potentioPin);
  Serial.println(potentioValue);
  delay(1000);

  pos2 = map(potentioValue, 0, 1023, 50, 180);
  servo.write(pos2);
  //delay(1000);

  if (pos2 < 90)
  {
 
    pos = pos + degree;
  
    if (pos < MIN_DISTANCE || pos > MAX_DISTANCE)
    {
      degree = -degree;
    }
  
    servo2.write(pos);

    if (notes[i] == ' ') {
      delay(beats[i] * tempo); // rest
    } else {
      playNote(notes[i], beats[i] * tempo);
    }

    i++;555;

    if (i > length)
    {
      i = 0;
    }
    // pause between notes
    delay(tempo / 2); 
  }
  else
  {
    pos = 50;
    servo2.write(pos);
    //no tone
  }
}

 

Musical Instrument

Me and Nisala started very ambitiously in our brainstorming session, but learned really fast that executing the theoretical ideas is a completely different thing. Instead of having a clear vision and linearly making it happen step by step, we experimented a lot with different sensors, materials and code. The process was very enjoyable, playful and although we ended up not using many of the elements we tried, we learned a bunch of new things (and how not to use them).

One of the major problems that got us stuck in the beginning was that the Tone and Servo library did not work together in one code – we solved it by creating a little bit more of tedious work for us and declared the notes and frequencies manually.

The beauty that was born eventually is a rotating music instrument that has a lot of paper clips inside. The main part of the instrument is a cardboard box, which is rotated by a servo, consequently making a lot of … music? (who said the music needs to be beautiful, right). Then we have a set of 8 buttons that together with a buzzer serve as a C major scale and that also control the servo. The degree to which the servo turn is determined by which button is pressed (the higher the note, the smaller the angle).

Here is a demonstration:

The breadboard: 

And lastly the code:

#include <Servo.h>


#define NOTE_C4 261
#define NOTE_D4 294
#define NOTE_E4 330
#define NOTE_F4 349
#define NOTE_G4 392
#define NOTE_A4 440
#define NOTE_B4 494
#define NOTE_C5 523

int duration = 500;

const int button1 = 4;
const int button2 = 5;
const int button3 = 6;
const int button4 = 7;
const int button5 = 8;
const int button6 = 9;
const int button7 = 10;
const int button8 = 12;

Servo servo;


const int buzzer = 3;


bool servoState = false;
int toggleTime = 0;
int triggerInterval = 500;
int angle = 0;

void setup() {
  // put your setup code here, to run once:

  pinMode (button1, INPUT);
  pinMode (button2, INPUT);
  pinMode (button3, INPUT);
  pinMode (button4, INPUT);
  pinMode (button5, INPUT);
  pinMode (button6, INPUT);
  pinMode (button7, INPUT);
  pinMode (button8, INPUT);

  servo.attach(11);

}

void loop() {
  // put your main code here, to run repeatedly:

  int buttonState1 = digitalRead(button1);
  int buttonState2 = digitalRead(button2);
  int buttonState3 = digitalRead(button3);
  int buttonState4 = digitalRead(button4);
  int buttonState5 = digitalRead(button5);
  int buttonState6 = digitalRead(button6);
  int buttonState7 = digitalRead(button7);
  int buttonState8 = digitalRead(button8);





  if (buttonState1 == HIGH) {
    tone(3, NOTE_C4);
    servo.write(180);

  }


  else if (buttonState2 == HIGH) {
    tone(3, NOTE_D4);
    servo.write(160);
  }



  else if (buttonState3 == HIGH) {
    tone(3, NOTE_E4);
    servo.write(140);
  }


  else if (buttonState4 == HIGH) {
    tone(3, NOTE_F4);
    servo.write(120);
  }



  else if (buttonState5 == HIGH) {
    tone(3, NOTE_G4);
    servo.write(100);
  }


  else if (buttonState6 == HIGH) {
    tone(3, NOTE_A4);
    servo.write(80);
  }



  else if (buttonState7 == HIGH) {
    tone(3, NOTE_B4);
    servo.write(60);
  }



  else if (buttonState8 == HIGH) {
    tone(3, NOTE_C5);
    servo.write(40);
  }


  else {
    noTone(3);
    servo.write(0);
  }

}

 

Reading response 2: The Psychopathology of Everyday Things

Design is such an important part of any object.

Norman has a very interesting perspective on design and touches on some thought provoking points. As a visual arts major, and someone who has dabbled in design a little bit, I understand the challenges that Norman talks about in relation to designers. Design is so important. It can either simplify, or complicate things for the users/audience, it can be interesting, aesthetic, minimalistic, boring, or complex. An navigating between the visual appeal of something and the efficiency and ease of use is up to the designer.

Norman talks about human centered design, which makes a lot of sense to me. An idea or product might be good in theory, but it might not be suited to the behavior of the average human. Furthermore another challenge for the designer is deciding how complex something should be. Norman talks about how adding more functions to something is supposed to make things easier by providing more options, but just complicates life. So a designer needs to decide the best balance between the two. It is very interesting to think of the development of design, and the new and unique design being developed for some products, while others stay relatively the same, and to think about how this will develop and change in the future.

Musical Instrument

For this week’s assignment, Steven and I created a machine that plays the drum and the piano.

To create the drum, we attached pairs of chopsticks on each servo motor and super-glued it together. We used a potentiometer to control the speed of the drumming; one hit the Pringles can and another was attached to a paper ball that made noise.

Some of the problems we came across was trying to make the piezo buzzer louder and also being able to control the speed of the servo motor based on the analog input of the potentiometer.  We are still unsure about how to make the piezo buzzer louder, but we think it might be because there isn’t enough voltage going through to the buzzer.

The Tone library and Servo library were also not allowed to be in the same program, which we did not know about in the beginning, so we had one Arduino program for controlling the servo and another to control the piezo buzzer.

Group project with Rick

Greetings friends!

For this weekly assignment, we have created a music buzzer with a bpm bird.

We have made the song “All star” using piano notes and tone.h to make
make it sound like the actual song. It took a long time to make it because I had to make a list of notes manually from the music score. Rick made a BPM bird using a servo to hit the beat once per 400ms, and in combination it sounded on sync. The problems that we’ve encountered was that servo.h and tone.h are not compatible with one another due to the inner-timer that these libraries use. We tried to look into the tone.h library to find the respective frequencies of the notes, but due to the delay issue, we had to separate the servo and the buzzer on separate Arduino boards to make it work properly.

Source Codes:

#include <Servo.h>

unsigned long previousMillis = 0;
const long interval = 7;
int angle = 0;

Servo myservo;

void setup() {
  myservo.attach(5);
}

void loop() {
  myservo.write(angle);
  unsigned long currentMillis = millis();
  if (currentMillis - previousMillis >= interval) {
    previousMillis = currentMillis;
    angle = (angle + 1) % 64;
  }
}
#include<Tone.h>
//                  0       1         2         3         4       5       6       7         8       9
int notes[11] = {NOTE_C4, NOTE_D4, NOTE_E4, NOTE_F4, NOTE_G4, NOTE_A4, NOTE_B4, NOTE_C5, NOTE_D5, NOTE_E5, 0};
int i = 0;
int duration[90] = {4, 2, 2, 4, 2, 2, 2, 4, 2, 2, 2, 2, 4, 2, 2, 2, 2, 2, 2, 2, 2, 6, 4,
                    2, 2, 2, 2, 2, 2, 2, 2, 2, 4, 2, 2, 2, 2, 2, 2, 4, 2, 2, 4, 2, 2, 4, 4, 4,
                    2, 4, 1, 1, 2, 4, 1, 1, 2, 4, 4, 2, 4, 2, 4, 1, 1, 2, 4, 1, 1, 2, 4, 4, 2, 4,
                    4, 4, 2, 2, 2, 8, 2, 2, 2, 2, 8, 4, 2, 4, 4, 16
                   };
int note[90] = {4, 8, 6, 6, 5, 4, 4, 7, 6, 6, 5, 5, 4, 4, 8, 6, 6, 5, 5, 4, 4, 2, 10,
                4, 4, 8, 6, 6, 5, 5, 4, 4, 7, 6, 6, 5, 5, 4, 4, 8, 6, 6, 5, 4, 4, 5, 2, 10,
                6, 4, 4, 2, 4, 4, 4, 2, 4, 4, 4, 6, 10, 6, 4, 4, 2, 4, 4, 4, 2, 4, 4, 4, 6, 10,
                6, 8, 7, 6, 5, 5, 4, 4, 5, 4, 6, 5, 4, 5, 2, 10
               };
Tone player;

void setup() {
  player.begin(3);
}

void loop() {
  player.play(notes[note[i % 90]], duration[i % 90] * 100);
  delay(duration[i % 90] * 100 + 20);
  i++;
}

 

Response: A Brief Rant on the Future of Interaction Design

Despite how it appears to the culture at large, technology doesn’t just happen. It doesn’t emerge spontaneously, pulling us helplessly toward some inevitable destiny.

In his Brief Rant on the Future of Interaction Design, Bret Victor urges people to move away from extrapolation of previous models of technology design, namely the “Pictures Under Glass” model which most of our hand-held devices and computers are structured around. He proposes that we should instead move towards a future that does not, in his words, ignore our hands. Most of us have a similar vague idea of what future technology is going to look like, and this is aided by what we see in different media such as popular futuristic films, or infomercial-style clips of technological breakthroughs. A lot of it is just a regurgitation of the technology we already have, recreated to fit other surfaces. Victor believes that we should instead create models that exceed our limited knowledge of human capability, but also models that fit right within the knowledge we currently have, which is that our hands are massively tactile and the visual component of our interactions with the world is minimal in comparison. More and more of our interactions with technology are becoming visual, and in a world where everything else we engage with is three-dimensional, this creates a gap between our sensory capabilities and the capabilities of the technology we’re designing. I must admit, this is something I have never really thought of- which is ultimately just proof of how seamlessly the culture of “pictures under glass” has become integrated into our lives.

Victor’s responses to some of the comments people left underneath his rant post were amusing, my favorite comment was “Yeah! iPhone bad! iPad bad!”, because his response to it really put things into perspective. He goes on to say how iPads are good -for now- because they are truly revolutionary for our time. What’s bad is that if in twenty years we still had the same model of the iPad with a few new functions and perhaps a new surface. I wholeheartedly agree with this statement, especially when looking back at the history of most technologies we use today. Many things started out as revolutionary but that did not stop people from searching beyond that.  What’s truly great is that we have control over our future, and as Victor said, it  “doesn’t emerge spontaneously, pulling us helplessly toward some inevitable destiny”. Through visions, research, multiple trials, and errors- we are able to control that destiny (at least for the most part). Therefore, I hope that our technology will soon evolve to encompass a wider range of our human capabilities, enhancing our lives in ways that were not previously possible.

Week 4 Circuits & Code – Analog Write, Servo, Buzzer, Tone Library

 

const int knobPin = A0;
const int ledPin = 3; // be sure to use a PWM pin!

void setup() {
  pinMode(ledPin, OUTPUT);
}

void loop() {
  // read the potentiometer value
  int knobValue = analogRead(knobPin);
  
  // analog write takes values between 0 and 255
  // map the knob value to be be between 0 and 255
  int brightness = map(knobValue,0,1023,0,255);

  // use the brightness value for the LED analog write
  analogWrite(ledPin, brightness);
}

 

 

#include <Servo.h>

Servo myServo;

const int knobPin = A0;

void setup() {
  // attach the servo to pin number 9
  myServo.attach(9);

}

void loop() {
  // read the potentiometer value
  int knobValue = analogRead(knobPin);
  
  // the servo only moves between 0 and 180
  // map the knob value to be be between 0 and 180
  int angle = map(knobValue,0,1023,0,180);

  // use the mapped angle to set the servo's rotation
  myServo.write(angle);

  // wait a very short bit for the servo to move to the location
  delay(15);
}

 

 

int buzzerPin = 4;

void setup() {
  pinMode(buzzerPin, OUTPUT);
}

void loop() {
  // arguments are pin, frequency, and duration
  tone(buzzerPin, 440, 200);
  // since the tone is lasting 200 milliseconds
  // delay for 400, so 200 on and then 200 off
  delay(400);

  // you could also do without the duration argument if you wanted a steady tone:
  //  tone(buzzerPin, 440);
}

Install the Tone Library by Brett Hagman to use more than one Buzzer:

// install the Tone Library by Brett Hagman to use multiple buzzers

#include <Tone.h>

// arrays to hold the note values
int notes[10] = {NOTE_C4, NOTE_D4, NOTE_E4, NOTE_F4, NOTE_G4, NOTE_A4, NOTE_B4, NOTE_C5, NOTE_D5, NOTE_E5};

Tone player0, player1;

// length in milliseconds
int duration = 250;

//variable to change note for player0
int whichNote = 0;

void setup() {
  // use pin 5 for buzzer 0
  player0.begin(5);
  // use pin 6 for buzzer 1
  player1.begin(6);
}

void loop() {
  // player0's notes change according to the number in whichNote
  player0.play(notes[whichNote], duration);

  // player1's note stays the same
  player1.play(notes[9], duration);

  // set whichNote to equal itself + 1
  // then modulo that number by 8, which creates a loop between 0-7 (8 digits)
  whichNote = (whichNote + 1) % 8; //do plus 1 to go up major scale, try others numbers like plus 3

  //wait for the notes to stop playing before going to the next note
  delay(duration);
}

 

 

 

Response to the Response for A Brief Rant on the Future of Interactive Design

Some interesting points Victor made about others’ responses are:

iPad is good: After his first blog post, I did not expect him to say that iPads/iPhones are good for now. It seemed that he was against the whole idea of a screen, but regardless, it makes me question what the timeline is for when a certain technology is no longer innovative. At what point do we say a screen is not enough?

What about voice: I’m not sure when this post was made, but I wonder what Victor’s opinions on recent technologies like Alexa are because the technology definitely fit his idea of interested using “tools for creating and understanding.”

What about brain interfaces: I agree with Victor about how computers are pretty much controlling our body and how our daily activities will soon be dominated by computer controlled in some way or another. It’s what many people are worried about, but how does Victor want to address this? What future interaction design can be made in the future that would stop this from happening?

My child can’t tie his shoelaces, but can use the iPad: I felt the point he made here was a harsh. He says that using screen technology is similar to restricting literature to Dr. Seuss’s vocabulary as if that was bad. He says that a “fully-functioning adult human being deserves so much more.” However, isn’t the whole point of interactive designs to be simple and not overdone? Humans are looking to make their life simpler; a lot of people would rather read Dr. Seuss’s book than to have to read Shakespeare.