The Potato Instrument functions very similarly to how a piano(?) would function. Tap a key (which in this case was a potato) and it would play a note that was coded in. The original intention for this was to play a note based on a button press using the pins that were being touched as a note adjuster, very similarly to a guitar or violin. Unfortunately, this was a little out of my element, and I decided with simple keys and did out with the button. The enclosure was going to be a box that had holes for each specific potato, but due to some issues the box was scrapped unfortunately. So essentially, when a potato is touched, a key plays. That is really as simple as it gets. The current potatos are attached to A3, A4, and A5 and play G, A, and B respectively on the 4th octave. To assure that the user would be exerting enough pressure to actually trigger a sound, a neopixel would turn on. Although the feedback itself should just be the sound coming out of the CPE, I found having a light turn on also told the user which specific key they were playing. If they somehow accidentally triggered another potato, we would know. The servo is playing all the time, it was originally intended to be a beat counter but I felt that the noise it made helped out as shown in the video below. Please excuse the cat.
Video Demonstration
Code
#include <Adafruit_CircuitPlayground.h>
#include "pitches.h" //borrows a library of pitches from an adafruit tutorial
int thresh =900; //pressure needed to activate keys
Servo myServo;
uint8_t keys[]={A2,A3,A4,A5,A6,A7}; //setting up the keys
int noteToPlay = NOTE_D4;//default note to play
int noteDuration=250; //note length
void setup() {
Serial.begin(9600);
delay(1000);
CircuitPlayground.begin();
myServo.attach(6); //A1 -- attaches servo
}
boolean touched (int t){ //boolean to check if pins have met the threshhold or not
if (t<thresh){
return true;
} else{
return false;
}
}
void loop(){
for (int p=A2; p<=A7; p++) {
Serial.println(CircuitPlayground.readCap(A4));
if(touched(CircuitPlayground.readCap(p)))
{
CircuitPlayground.setPixelColor(p-14,0,0,0);
}
else{
CircuitPlayground.setPixelColor(p-14,0,0,30); //neopixel feedback/decides which sound is played based on which pin is touched
switch(p){
//case A1:noteToPlay=NOTE_E4;
// break;
case A2:noteToPlay=NOTE_FS4;
break;
case A3:noteToPlay=NOTE_G4;
break;
case A4:noteToPlay=NOTE_A4;
break;
case A5:noteToPlay=NOTE_B4;
break;
case A6:noteToPlay=NOTE_C5;
break;
case A7:noteToPlay=NOTE_D5;
break;
default:noteToPlay=NOTE_D4;
}
CircuitPlayground.playTone(noteToPlay,noteDuration);
}
}
noteToPlay=NOTE_D4; //at the end of every loop, the note returns to the default note
}
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.