Piano Keyboard

by 苳梣 in Circuits > Arduino

345 Views, 1 Favorites, 0 Comments

Piano Keyboard

鋼琴.PNG

It will need to use with the website that you need to play the piano with your computer keyboard.

The website that I use >> link

Supplies

  • Arduino board
  • small button x12
  • 120 Ohm Resistor x12

Set Up the Circuit

擷取......PNG

You just need to connect the button to D1 to D13, except D4. D4 needs to connect with GND.

Uploading the Code

#include <Keyboard.h>

/*
 These core libraries allow the 32u4 and SAMD based boards 
 (Leonardo, Esplora, Zero, Due and MKR Family) 
 to appear as a native Mouse and/or Keyboard to a connected computer.
 */

void setup(){  // put your setup code here, to run once:
  pinMode( 2 , INPUT);   // sets the digital pin as input
  Keyboard.begin(); // initialize control over the keyboard
  Keyboard.releaseAll();

  pinMode( 3 , INPUT);   // sets the digital pin as input
}

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

    pinMode(4,INPUT_PULLUP); 
    if(digitalRead(4)==LOW){ 
      Keyboard.press('t'); 
    }
  }
  else  {
    Keyboard.releaseAll();
  }
  delay( 100 ); 
  if (digitalRead( 2 )) {

    pinMode(4,INPUT_PULLUP); 
    if(digitalRead(4)==LOW){ 
      Keyboard.press(129); 
    }
    pinMode(4,INPUT_PULLUP);
    if(digitalRead(4)==LOW){  
      Keyboard.press('t'); 
    }
  }
  else  {
    Keyboard.releaseAll();
  }  //DO
  if (digitalRead( 3 )) {

    pinMode(4,INPUT_PULLUP); 
    if(digitalRead(4)==LOW){ 
      Keyboard.press('y'); 
    }
  }
  else  {
    Keyboard.releaseAll();
  }
  delay( 100 ); 
  if (digitalRead( 5 )) {

    pinMode(4,INPUT_PULLUP); 
    if(digitalRead(4)==LOW){ 
      Keyboard.press(129); 
    }
    pinMode(4,INPUT_PULLUP);
    if(digitalRead(4)==LOW){  
      Keyboard.press('y'); 
    }
  }
  else  {
    Keyboard.releaseAll();
  }  //RE
  if (digitalRead( 6 )) {

    pinMode(4,INPUT_PULLUP); 
    if(digitalRead(4)==LOW){ 
      Keyboard.press('u'); 
    }
  }
  else  {
    Keyboard.releaseAll();
  }  //MI
  if (digitalRead( 7 )) {

    pinMode(4,INPUT_PULLUP); 
    if(digitalRead(4)==LOW){ 
      Keyboard.press('i'); 
    }
  }
  else  {
    Keyboard.releaseAll();
  }
  delay(100);
  if (digitalRead( 8 )) {

    pinMode(4,INPUT_PULLUP); 
    if(digitalRead(4)==LOW){ 
      Keyboard.press(129); 
    }
    pinMode(4,INPUT_PULLUP);
    if(digitalRead(4)==LOW){  
      Keyboard.press('i'); 
    }
  }
  else  {
    Keyboard.releaseAll();
  } //FA
  if (digitalRead( 9 )) {

    pinMode(4,INPUT_PULLUP); 
    if(digitalRead(4)==LOW){ 
      Keyboard.press('o'); 
    }
  }
  else  {
    Keyboard.releaseAll();
  }
  delay( 100 ); 
  if (digitalRead( 10 )) {

    pinMode(4,INPUT_PULLUP); 
    if(digitalRead(4)==LOW){ 
      Keyboard.press(129); 
    }
    pinMode(4,INPUT_PULLUP);
    if(digitalRead(4)==LOW){  
      Keyboard.press('o'); 
    }
  }
  else  {
    Keyboard.releaseAll();
  } //SO
  if (digitalRead( 11 )) {

    pinMode(4,INPUT_PULLUP); 
    if(digitalRead(4)==LOW){ 
      Keyboard.press('p'); 
    }
  }
  else  {
    Keyboard.releaseAll();
  }
  if (digitalRead( 12 )) {

    pinMode(4,INPUT_PULLUP); 
    if(digitalRead(4)==LOW){ 
      Keyboard.press(129); 
    }
    pinMode(4,INPUT_PULLUP);
    if(digitalRead(4)==LOW){  
      Keyboard.press('p'); 
    }
  }
  else  {
    Keyboard.releaseAll();
  } //LA
  if (digitalRead( 13 )) {

    pinMode(4,INPUT_PULLUP); 
    if(digitalRead(4)==LOW){ 
      Keyboard.press('a'); 
    }
  }
  else  {
    Keyboard.releaseAll();
  } //SI
}

At the end of the code, I have marked out which pitch is it belong to.

I have a problem up here, I still can't found out and correct it before the deadline for my H.W.

The problem is that there has some button you can't send out the letter I want it to have. Some of them can send it out, but they will send out the wrong letter, or just didn't send anything out. Oh, and they will delay some time.

If you can, please help me fix out this question. 🥺

Downloads

How to Use If It Done

鋼琴.PNG

After you have done it you can press on the keyboard that you make with your Arduino and the letter corresponding to the pitch is on the picture, if you still don't know, you can press the key on the screen with your mouse, it will show up at the black block.