Skip to content

Instantly share code, notes, and snippets.

@Honga1
Created March 3, 2018 14:21
Show Gist options
  • Save Honga1/f234ea8df51752eae5b442f1bfd038e4 to your computer and use it in GitHub Desktop.
Save Honga1/f234ea8df51752eae5b442f1bfd038e4 to your computer and use it in GitHub Desktop.
Arduino code to follow X position water bath as linear resistor and output a tone.
void setup() {
// initialize serial communications (for debugging only):
Serial.begin(9600);
pinMode(7, OUTPUT); //Left Plate
pinMode(6, OUTPUT); //Right plate
}
int sens_flip = 0;
int av = 0;
void loop() {
//Flips between plate to stop charge buildup on either side through ion migration
if (sens_flip > 0) {
digitalWrite(6, HIGH); //L PLate
digitalWrite(7, LOW); //R Plate
sens_flip--;
delay(10);
} else {
sens_flip++;
digitalWrite(7, HIGH);
digitalWrite(6, LOW);
delay(10);
int sensorReading = analogRead(A0);
av = sensorReading + 30*av; //Average the sensor reading
av /= 31;
Serial.println(sensorReading);
int thisPitch = map(av, 0, 1024, 120, 1500);
// play the pitch:
tone(9, thisPitch);
}
delay(10);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment