Created
March 3, 2018 14:21
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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