Created
November 5, 2015 16:03
-
-
Save paulhayes/b814052d1a9325fda0a5 to your computer and use it in GitHub Desktop.
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
#include <CapacitiveSensor.h> | |
CapacitiveSensor cs = CapacitiveSensor(9,2); // 10M resistor between pins 4 & 2, pin 2 is sensor pin, add a wire and or foil if desired | |
int minValue = 32767; | |
int maxValue = 0; | |
void setup(){ | |
cs.set_CS_AutocaL_Millis(0xFFFFFFFF); // turn off autocalibrate on channel 1 - just as an example | |
Serial.begin(9600); | |
} | |
void loop(){ | |
long start = millis(); | |
long total = cs.capacitiveSensor(30); | |
minValue = min(total,minValue); | |
if(minValue<total){ | |
minValue++; | |
} | |
maxValue = max(total,maxValue); | |
float value = 1.0 * (total-minValue) / (maxValue - minValue); | |
Serial.print(millis() - start); // check on performance in milliseconds | |
Serial.print("\t"); // tab character for debug windown spacing | |
delay(10); // arbitrary delay to limit data to serial port | |
Serial.print(total); | |
Serial.print("\t"); | |
Serial.println(value); | |
tone(10,(1200*value)+400); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment