Hey everyone,
Super beginner at this and am looking for some help. This for a school project, and advice would be great.
Basically I'm trying to play different melodies depending on the amount of pressure you apply on conductive foam (soon to be a FSR sensor). I've played with the code for hours and can't seem to reach anywhere but playing an annoying tone and changing the pitch.
The value in sensorReading will be between 0 and 1023. You have defined actions to be performed in the 8 note loop for only 3 of those values (1, 2, and 3). You need 1,021 more case statements.
The idea for the final outcome for the project will be basically a target with 3 different rings, depending on which ring the shooter hits i want a different sound played. To do this the sensor will be mounted behind the bullseye, the pressure will be the greatest if they hit the bullseye vs the outer ring. I need the arduino to measure the pressure and play a corresponding melody depending upon which ring they hit on the target.
if(someCondition == true)
{
// Do thing 1
// Do thing 2
// Do thing 3
}
Would this still work then, hearing what i want to achieve? I though the if statement was like a fork in a road, you could only go one direction or another. Or would inside the "Do thing " would that be where it measures the pressure and executes the melody?
Perhaps you need to worry less about the playMelody() function that you will write, and more about the validity of the assumption that "the pressure will be the greatest if they hit the bullseye vs the outer ring."
Create a sketch to read and print the value from analogRead, after you have connected the sensor. Shoot at the bullseye and other rings, and see if you get a clear relationship between the point hit and the reading.
If you do, then you really only have one thing to do - play a tune. Which tune to play will depend on the sensor reading. Create one function, playMelody() that takes an argument to define which melody to play (1, 2, or 3).
Have playMelody() call playMelody1(), playMelody2(), or playMelody3(). Then, have each playMelodyN() function play some (different) series of notes.