Damlanur 5 years ago
parent 2a5a440056
commit da4c398d7f

@ -0,0 +1,35 @@
//controlling pitch of tones with pin 1
void setup() {
// put your setup code here, to run once:
int i = 0; //to stop playback after it reaches a certain amount of loops
int x = analogRead(1); //get pin 1's value
x = map(x, 0, 1023, 1, 50); //map the value (which is between 0 and 1023 to between 1 and 50
Serial.begin(9600); //serial for debugging
Serial.println("hello");
Serial.println("counter is now");
Serial.println(i);
while (i < 100){ //it will stop playing after counter reaches to 100
tone(11, random(100,200)*x, 200); //play a random tone frequency of which is determined by multiplying a number between 100 and 200 with the x value
delay(50);
tone(11, random(100,400)*x, 200);
delay(50);
tone(11, random(100,600)*x, 200);
delay(50);
i = i + 1; //count up
x = analogRead(1); //get knob value again
x = map(x, 0, 1023, 1, 50);
Serial.println("counter is now");
Serial.println(i);
}
}
void loop() {
}
Loading…
Cancel
Save