All pastes #2072475 Raw Edit

Arduino potentiometer/piezo inst

public c v1 · immutable
#2072475 ·published 2011-05-30 21:19 UTC
rendered paste body
int 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. }