Components and supplies
Speaker, 8 Ohm
Resistor 220 ohm
Breadboard (generic)
Alligator Clips
Resistor 2.2 M Ohm, 1/4 Watt
Flat Ribbon Cable Jumper Wire, 30 cm
Arduino UNO
Apps and platforms
Arduino IDE
Project description
Code
pitches.h
c_cpp
pitches.h from Arduino IDE code examples
1/************************************************* 2 * Public Constants 3 *************************************************/ 4 5#define NOTE_B0 31 6#define NOTE_C1 33 7#define NOTE_CS1 35 8#define NOTE_D1 37 9#define NOTE_DS1 39 10#define NOTE_E1 41 11#define NOTE_F1 44 12#define NOTE_FS1 46 13#define NOTE_G1 49 14#define NOTE_GS1 52 15#define NOTE_A1 55 16#define NOTE_AS1 58 17#define NOTE_B1 62 18#define NOTE_C2 65 19#define NOTE_CS2 69 20#define NOTE_D2 73 21#define NOTE_DS2 78 22#define NOTE_E2 82 23#define NOTE_F2 87 24#define NOTE_FS2 93 25#define NOTE_G2 98 26#define NOTE_GS2 104 27#define NOTE_A2 110 28#define NOTE_AS2 117 29#define NOTE_B2 123 30#define NOTE_C3 131 31#define NOTE_CS3 139 32#define NOTE_D3 147 33#define NOTE_DS3 156 34#define NOTE_E3 165 35#define NOTE_F3 175 36#define NOTE_FS3 185 37#define NOTE_G3 196 38#define NOTE_GS3 208 39#define NOTE_A3 220 40#define NOTE_AS3 233 41#define NOTE_B3 247 42#define NOTE_C4 262 43#define NOTE_CS4 277 44#define NOTE_D4 294 45#define NOTE_DS4 311 46#define NOTE_E4 330 47#define NOTE_F4 349 48#define NOTE_FS4 370 49#define NOTE_G4 392 50#define NOTE_GS4 415 51#define NOTE_A4 440 52#define NOTE_AS4 466 53#define NOTE_B4 494 54#define NOTE_C5 523 55#define NOTE_CS5 554 56#define NOTE_D5 587 57#define NOTE_DS5 622 58#define NOTE_E5 659 59#define NOTE_F5 698 60#define NOTE_FS5 740 61#define NOTE_G5 784 62#define NOTE_GS5 831 63#define NOTE_A5 880 64#define NOTE_AS5 932 65#define NOTE_B5 988 66#define NOTE_C6 1047 67#define NOTE_CS6 1109 68#define NOTE_D6 1175 69#define NOTE_DS6 1245 70#define NOTE_E6 1319 71#define NOTE_F6 1397 72#define NOTE_FS6 1480 73#define NOTE_G6 1568 74#define NOTE_GS6 1661 75#define NOTE_A6 1760 76#define NOTE_AS6 1865 77#define NOTE_B6 1976 78#define NOTE_C7 2093 79#define NOTE_CS7 2217 80#define NOTE_D7 2349 81#define NOTE_DS7 2489 82#define NOTE_E7 2637 83#define NOTE_F7 2794 84#define NOTE_FS7 2960 85#define NOTE_G7 3136 86#define NOTE_GS7 3322 87#define NOTE_A7 3520 88#define NOTE_AS7 3729 89#define NOTE_B7 3951 90#define NOTE_C8 4186 91#define NOTE_CS8 4435 92#define NOTE_D8 4699 93#define NOTE_DS8 4978 94 95 96
pitches.h
c_cpp
pitches.h from Arduino IDE code examples
1/************************************************* 2 * Public Constants 3 4 *************************************************/ 5 6#define NOTE_B0 31 7#define 8 NOTE_C1 33 9#define NOTE_CS1 35 10#define NOTE_D1 37 11#define NOTE_DS1 39 12#define 13 NOTE_E1 41 14#define NOTE_F1 44 15#define NOTE_FS1 46 16#define NOTE_G1 49 17#define 18 NOTE_GS1 52 19#define NOTE_A1 55 20#define NOTE_AS1 58 21#define NOTE_B1 62 22#define 23 NOTE_C2 65 24#define NOTE_CS2 69 25#define NOTE_D2 73 26#define NOTE_DS2 78 27#define 28 NOTE_E2 82 29#define NOTE_F2 87 30#define NOTE_FS2 93 31#define NOTE_G2 98 32#define 33 NOTE_GS2 104 34#define NOTE_A2 110 35#define NOTE_AS2 117 36#define NOTE_B2 37 123 38#define NOTE_C3 131 39#define NOTE_CS3 139 40#define NOTE_D3 147 41#define 42 NOTE_DS3 156 43#define NOTE_E3 165 44#define NOTE_F3 175 45#define NOTE_FS3 46 185 47#define NOTE_G3 196 48#define NOTE_GS3 208 49#define NOTE_A3 220 50#define 51 NOTE_AS3 233 52#define NOTE_B3 247 53#define NOTE_C4 262 54#define NOTE_CS4 55 277 56#define NOTE_D4 294 57#define NOTE_DS4 311 58#define NOTE_E4 330 59#define 60 NOTE_F4 349 61#define NOTE_FS4 370 62#define NOTE_G4 392 63#define NOTE_GS4 64 415 65#define NOTE_A4 440 66#define NOTE_AS4 466 67#define NOTE_B4 494 68#define 69 NOTE_C5 523 70#define NOTE_CS5 554 71#define NOTE_D5 587 72#define NOTE_DS5 73 622 74#define NOTE_E5 659 75#define NOTE_F5 698 76#define NOTE_FS5 740 77#define 78 NOTE_G5 784 79#define NOTE_GS5 831 80#define NOTE_A5 880 81#define NOTE_AS5 82 932 83#define NOTE_B5 988 84#define NOTE_C6 1047 85#define NOTE_CS6 1109 86#define 87 NOTE_D6 1175 88#define NOTE_DS6 1245 89#define NOTE_E6 1319 90#define NOTE_F6 91 1397 92#define NOTE_FS6 1480 93#define NOTE_G6 1568 94#define NOTE_GS6 1661 95#define 96 NOTE_A6 1760 97#define NOTE_AS6 1865 98#define NOTE_B6 1976 99#define NOTE_C7 100 2093 101#define NOTE_CS7 2217 102#define NOTE_D7 2349 103#define NOTE_DS7 2489 104#define 105 NOTE_E7 2637 106#define NOTE_F7 2794 107#define NOTE_FS7 2960 108#define NOTE_G7 109 3136 110#define NOTE_GS7 3322 111#define NOTE_A7 3520 112#define NOTE_AS7 3729 113#define 114 NOTE_B7 3951 115#define NOTE_C8 4186 116#define NOTE_CS8 4435 117#define NOTE_D8 118 4699 119#define NOTE_DS8 4978 120 121 122
BananaPiano.ino
c_cpp
This is the main program to drive the banana piano. It uses pitches.h.
1/* 2 Banana Piano 3 4 This code implements a single octave of a simple piano. It borrows from Tom Igoe's tone 5 example ( http://arduino.cc/en/Tutorial/Tone ) and uses his pitches.h include file for 6 the note frequencies. The digital input pins and their corresponding notes are defined 7 in arrays. Serial monitor output is provided to test key logic levels. 8 9 The digital inputs use 2.2 Meg Ohm pull-up resistors. The digital inputs are brought to 10 logic level LOW by grounding the banana connected to each digital input. 11 12 Circuit: 13 8 - 2.2 Meg Ohm pull-up resistors, connected to +5 V and each of the digital input pins 14 1 - 220 Ohm resistor, connected from pin 12 to an 8 Ohm speaker 15 16 R. Ballew, 31-Jan-2018 17 18*/ 19#include "pitches.h" 20 21int numKeys = 8; 22int digInput[] = { 2, 3, 4, 5, 6, 7, 8, 9 }; 23int myNote[] = { NOTE_C4, NOTE_D4, NOTE_E4, NOTE_F4, NOTE_G4, NOTE_A4, NOTE_B4, NOTE_C5 }; 24int toneOut = 12; 25 26void setup() { 27 // Start serial connection 28 Serial.begin(9600); 29 // Configure digital input pins 30 for (int i = 0; i < numKeys; i++) { 31 pinMode(digInput[i], INPUT); 32 } 33 pinMode(toneOut, OUTPUT); 34} 35 36void loop() { 37 // 38 int keypressed = 0; 39 for (int j = 0; j < numKeys; j++) { 40 int sensorVal = digitalRead(digInput[j]); 41 String outStr = String("K"); 42 outStr = String(outStr + j); 43 outStr = String(outStr + ": "); 44 outStr = String(outStr + sensorVal); 45 if (sensorVal == LOW) { 46 ++keypressed; // increment keypressed 47 digitalWrite(13, HIGH); 48 tone(toneOut, myNote[j]); 49 } 50 //outStr = String(outStr + ":"); 51 //outStr = String(outStr + keypressed); 52 Serial.print(outStr); 53 Serial.print("\ "); 54 } 55 Serial.println(""); 56 if (keypressed == 0) { 57 noTone(toneOut); 58 } 59 delay(250); 60} 61
Downloadable files
Schematic
Banana Piano Circuit Schematic
Schematic
Schematic
Banana Piano Circuit Schematic
Schematic
Comments
Only logged in users can leave comments