Arduino potentiometer/piezo inst
public c v1 · immutableint val = 0;void setup() { pinMode(7, INPUT); //set up our push button}void loop() { val = analogRead(0); //reads the potentiometer information val = map(val, 0, 1023, -12, 13); //converts the value. -12 is an octave below the middle, 12 is an octave above. if(digitalRead(7)==1) //if button isn't pressed noTone(8); //turn off the piezo element else tone(8, pow(2,((double)val)/12)*440); //plays the note according to the position of the piezo element. }