0% found this document useful (0 votes)
8 views2 pages

BananaPiano Ino

The document describes a code implementation for a simple piano using Arduino, featuring a single octave with 8 keys. It includes details on the circuit setup, such as the use of pull-up resistors and a speaker connection, as well as the logic for detecting key presses and producing corresponding tones. The code utilizes the pitches.h library for note frequencies and outputs key states to the serial monitor for testing purposes.

Uploaded by

nhoxcathbox
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views2 pages

BananaPiano Ino

The document describes a code implementation for a simple piano using Arduino, featuring a single octave with 8 keys. It includes details on the circuit setup, such as the use of pull-up resistors and a speaker connection, as well as the logic for detecting key presses and producing corresponding tones. The code utilizes the pitches.h library for note frequencies and outputs key states to the serial monitor for testing purposes.

Uploaded by

nhoxcathbox
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

/*

Banana Piano

This code implements a single octave of a simple piano. It borrows from Tom
Igoe's tone
example ( http://arduino.cc/en/Tutorial/Tone ) and uses his pitches.h include
file for
the note frequencies. The digital input pins and their corresponding notes are
defined
in arrays. Serial monitor output is provided to test key logic levels.

The digital inputs use 2.2 Meg Ohm pull-up resistors. The digital inputs are
brought to
logic level LOW by grounding the banana connected to each digital input.

Circuit:
8 - 2.2 Meg Ohm pull-up resistors, connected to +5 V and each of the digital
input pins
1 - 220 Ohm resistor, connected from pin 12 to an 8 Ohm speaker

R. Ballew, 31-Jan-2018

*/
#include "pitches.h"

int numKeys = 8;
int digInput[] = { 2, 3, 4, 5, 6, 7, 8, 9 };
int myNote[] = { NOTE_C4, NOTE_D4, NOTE_E4, NOTE_F4, NOTE_G4, NOTE_A4, NOTE_B4,
NOTE_C5 };
int toneOut = 12;

void setup() {
// Start serial connection
Serial.begin(9600);
// Configure digital input pins
for (int i = 0; i < numKeys; i++) {
pinMode(digInput[i], INPUT);
}
pinMode(toneOut, OUTPUT);
}

void loop() {
//
int keypressed = 0;
for (int j = 0; j < numKeys; j++) {
int sensorVal = digitalRead(digInput[j]);
String outStr = String("K");
outStr = String(outStr + j);
outStr = String(outStr + ": ");
outStr = String(outStr + sensorVal);
if (sensorVal == LOW) {
++keypressed; // increment keypressed
digitalWrite(13, HIGH);
tone(toneOut, myNote[j]);
}
//outStr = String(outStr + ":");
//outStr = String(outStr + keypressed);
Serial.print(outStr);
Serial.print("\ ");
}
Serial.println("");
if (keypressed == 0) {
noTone(toneOut);
}
delay(250);
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy