KRIVANJADIYables
Published

Keyboard

Keyboard instrument using Piezo and Push Buttons

BeginnerProtip7,411
Keyboard

Things used in this project

Story

Read more

Schematics

Keyboard

Code

Keyboard

Arduino
/*
Keyboard
*/

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

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
if (keyVal == 1023) {
// play the first frequency in the array on pin 8
tone(8, notes[0]);
} else if (keyVal >= 990 && keyVal <= 1010) {
// play the second frequency in the array on pin 8
tone(8, notes[1]);
} else if (keyVal >= 505 && keyVal <= 515) {
// play the third frequency in the array on pin 8
tone(8, notes[2]);
} else if (keyVal >= 5 && keyVal <= 10) {
// play the fourth frequency in the array on pin 8
tone(8, notes[3]);
} else {
// if the value is out of range, play no tone
noTone(8);
}
}

Credits

KRIVANJA

KRIVANJA

37 projects • 52 followers
www.krivanja.dev
DIYables

DIYables

0 projects • 64 followers
I would like to invite you to join and add your projects to DIYables platform https://www.hackster.io/diyables

Comments