strupf
Published © GPL3+

Keyboard 6 keys (pimped p07)

The keyboard from the basic starter kit using 6 pushbuttons

BeginnerProtip482
Keyboard 6 keys (pimped p07)

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Speaker, Piezo
Speaker, Piezo
×1
Resistor 220 ohm
Resistor 220 ohm
×1
Through Hole Resistor, 560 ohm
Through Hole Resistor, 560 ohm
×1
Resistor 1k ohm
Resistor 1k ohm
×1
Arduino Resistor 4.7 kOhm
×2
Resistor 10k ohm
Resistor 10k ohm
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Tactile Switch, Top Actuated
Tactile Switch, Top Actuated
×6

Story

Read more

Schematics

Keyboard 6 keys

Pimped up keyboard from the starter kit

Code

Keyboard from the starter kit using 6 pushbuttons

Arduino
Keyboard C, D, E, F, G, A
// create an array of notes
// the numbers below correspond to the frequencies of middle C, D, E, F, G and A
int notes[] = {262, 294, 330, 349, 392, 440};

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

void loop() {
  // create a local variable to hold the input on pin A0
  int keyVal = analogRead(A0);
  // send the value from A0 to the Serial Monitor
  Serial.println(keyVal);

  // play the note corresponding to each value on A0 (0 Ohm)
  if (keyVal == 1023) {
    // play the first frequency in the array on pin 8
    tone(8, notes[0]);
  } else if (keyVal >= 970 && keyVal <= 1010) {
    // play the second frequency in the array on pin 8 (220 Ohm)
    tone(8, notes[1]);
  } else if (keyVal >= 900 && keyVal <= 920) {
    // play the third frequency in the array on pin 8 (560 Ohm)
    tone(8, notes[2]);
  } else if (keyVal >= 840 && keyVal <= 850) {
    // play the fourth frequency in the array on pin 8 (1 kOhm)
    tone(8, notes[3]);
  } else if (keyVal >= 500 && keyVal <= 520) {
    // play the fourth frequency in the array on pin 8 (4.7 kOhm)
    tone(8, notes[4]);
  } else if (keyVal >= 300 && keyVal <= 350) {
    // play the fourth frequency in the array on pin 8 (10 kOhm)
    tone(8, notes[5]);
  } else {
    // if the value is out of range, play no tone
    noTone(8);
  }
}

Credits

strupf
0 projects • 0 followers
Contact

Comments

Please log in or sign up to comment.