After watching the videos on changes and developments in music in class, I got to thinking about what would be a cool, funky way to make music with electronics. I decided that a fun experimental music making idea would combine the ability to change the type of sound quickly on a speaker (frequency) as well as add in the taps that could go with a beat based on your leg moving up and down. This being triggered by your leg would leave a hand open to change out what is being tapped by the solenoid and thus change the sound heard from it. As someone who knows nothing about music and notes, I chose for someone to just change the frequency so that there would be no barriers from someone trying it out. For this proof of concept, I chose to have the speaker turn off when the IR beam is broken and the solenoid moves as it overpowers the sound otherwise.
int solenoidPin = 9;
const int IRpin = 3;
int IRstate;
int potPin = A0;
int potVal;
int speakerPin = 13;
int frequency;
void setup()
{
pinMode(solenoidPin, OUTPUT);
pinMode(IRpin, INPUT);
digitalWrite(IRpin, HIGH);
pinMode(potPin, INPUT);
pinMode(speakerPin, OUTPUT);
Serial.begin(9600);
}
void loop()
{
potVal = analogRead(potPin);
frequency = map(potVal, 0, 1023, 1, 1000);
IRstate = digitalRead(IRpin);
Serial.println(IRstate);
static int start = millis();
digitalWrite(solenoidPin, !IRstate);
if (IRstate == 1) {
tone(speakerPin, frequency);
}
else { //broken
noTone(speakerPin);
}
}