int force0; //force for pins A0-A3
int force1;
int force2;
int force3;
int forcePin0 = 0; //define pins A0-A3
int forcePin1 = 1;
int forcePin2 = 2;
int forcePin3 = 3;
void setup() {
pinMode(8, OUTPUT); //Pin for the buzzer
Serial.begin(9600);
}
void loop() {
force0 = analogRead(forcePin0); //setting forces equal to the readings from pins A0-A3
force1 = analogRead(forcePin1);
force2 = analogRead(forcePin2);
force3 = analogRead(forcePin3);
if (force0 > 50) //If the force sensitive resistor reads greater than 50
{
tone(8, 10, 200); //Then play this tobe
delay(100); //delay breaks tone up to make it sound like a quick repetive tap
//instead of simply a tone. This gives it a more drum-y sound
}
else if (force1 > 50)
{
tone(8, 20000, 500);
delay(100);
}
else if (force2 > 50)
{
tone(8, 90, 20);
delay(100);
}
else if (force3 > 50)
{
tone(8, 20, 200);
delay(100);
}
else
{
noTone(8);
}
}
No comments:
Post a Comment