Exercise 3 – Two note keyboard with pitch modulation

Author: Matthew Conlen

This project uses an arduino board with two push buttons, a flex sensor and a speaker.

The two buttons act as input like notes on a keyboard. The flex sensor allows the user to “bend” the notes.

The tone library used can be found here: http://code.google.com/p/rogue-code/wiki/ToneLibraryDocumentation

#include

Tone tone1, tone2;
int buttonState = 0;
int flexValue = 0;

int notes[] = {
NOTE_A3, NOTE_A4};

void setup()
{
tone1.begin(8);
tone2.begin(8);
Serial.begin(9600);
}

void loop()
{
flexValue = analogRead(0);
if (flexValue > 288)
flexValue = map(flexValue, 288, 310, 0, 50);
else
flexValue = map(flexValue, 90, 288, -50, 0);
flexValue = constrain(flexValue, -50, 50);
Serial.println(flexValue);
if(digitalRead(2) == HIGH) {
tone1.play(notes[0] + flexValue);
}
else
tone1.stop();
if(digitalRead(3) == HIGH) {
tone2.play(notes[1] + flexValue);
}
else
tone2.stop();
}

Comments are closed.