Concept:
For my instrument, I used three different sensors. The force meter, potentiometer, and a switch. Originally, I wanted to read different inputs using a motor, but since I couldn’t, I used the potentiometer as the main dial that read the input to translate into pitches. The input from force meter would then decide on whether to play the notes and in which octave. The switch would change the mode of the instrument from playing designated musical notes to free range pitch.
Video:
Code:
int pitch; int force = 0; int note = 0; int switchInstrument; #include <ezButton.h>; ezButton toggleSwitch(7); #include "pitches.h"; int melody[] = { NOTE_C2, NOTE_D2, NOTE_E2, NOTE_F2, NOTE_G2, NOTE_A2, NOTE_B2, NOTE_C3, NOTE_D3, NOTE_E3, NOTE_F3, NOTE_G3, NOTE_A3, NOTE_B3, NOTE_C4, NOTE_D4, NOTE_E4, NOTE_F4, NOTE_G4, NOTE_A4, NOTE_B4, NOTE_C5, NOTE_D5, NOTE_E5, NOTE_F5, NOTE_G5, NOTE_A5, NOTE_B5 }; void setup() { // put your setup code here, to run once: Serial.begin(9600); toggleSwitch.setDebounceTime(50); pinMode(8, OUTPUT); } void loop() { toggleSwitch.loop(); readPitch(); readForce(); int state = toggleSwitch.getState(); if(state == HIGH){ Serial.println("The switch: OFF"); if(force < 10) noTone(8); else if(force < 200){ tone(8, melody[note]); } else if(force < 500){ tone(8, melody[note + 7]); } else if(force < 800){ tone(8, melody[note + 14]); } else{ tone(8, melody[note + 21]); } } else{ if(force > 10) tone(8, pitch + force); } } void readPitch(){ pitch = analogRead(A5); if(pitch < 150) note = 0; else if(pitch < 300) note = 1; else if(pitch < 450) note = 2; else if(pitch < 600) note = 3; else if(pitch < 750) note = 4; else if(pitch < 900) note = 5; else note = 6; } void readForce(){ force = analogRead(A0); }
How it works:
When the switch is off, the potentiometer takes care of the main pitch from the range of notes of C to B. By turning the dial of the potentiometer from low to high, the instruments will play the notes from C to B. Then, the force meter, depending on how strong the force input is, decides on the octave of the note. For example, in my code, if force input is lower than 500 but higher than 200, it will play notes in the range of C3 to B3. All the notes are preloaded in the notes array before setup, and in this mode of the instrument, it only plays those designated musical notes. When the switch in on, the instrument will be put on a different mode where the pitch is not limited to a designated note but will be a number combined by the current potentiometer input and the force meter input. Therefore, the pitch made from this mode can be freely chosen by how strong you press the force meter and what the dial of the potentiometer is pointing at.
Future Improvements:
In the future, I would like to use some other dial format analog sensor like the motor I initially planned. I would also think of some other creative ways to use other sensors like the bend sensor or etc.. While I used the alligator clips to incorporate the switch to my circuit, later in the future I would also like to learn soldering so I can stably add more sensors to my circuit.