/*
Squishy Speaker
Code written by Sam Johnson for the Squishy Circiuts
Project with AnnMarie Thomas
*/

int analogPin = 0; // common resistor connected to analog pin 0
// outside leads to ground and +5V
int raw = 0; // variable to store the raw input value
int Vin = 5; // variable to store the input voltage
float Vout = 0; // variable to store the output voltage
float R1 = 1191; // variable to store the R1 value (known resistor)
float R2 = 0; // variable to store the R2 value (resistance of dough)
float buffer = 0; // buffer variable for Hz/Ohm calculation

void setup()
{
Serial.begin(9600); // Setup serial
}

void loop()
{
raw = analogRead(analogPin); // Reads the Input PIN voltage
Vout = (5.0 / R1) * raw; // Calculates the Voltage on th Input PIN
buffer = (Vin / Vout) - 1;
R2 = R1 / buffer;
tone(9,R2-3000,250); // Plays tone
// To adjust for a proper tone change the '3000'
// To change tone range substitute the subtraction ("R2-3000) with product (ex: R2*1.5)
}