Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // code patched together from examples
- // by Les Hall
- // started Wed May 20 2015
- //
- #include <CapacitiveSensor.h>
- CapacitiveSensor cs1 = CapacitiveSensor(4,3);
- CapacitiveSensor cs2 = CapacitiveSensor(4,5);
- int inByte = 0; // incoming serial byte
- long total1; // Capacitance sense value
- long total2; // Capacitance sense value
- void setup()
- {
- //cs1.set_CS_AutocaL_Millis(0xFFFFFFFF); // turn off autocalibrate on channel 1 - just as an example
- pinMode(9, OUTPUT);
- Serial.begin(9600);
- establishContact(); // send a byte to establish contact until receiver responds
- }
- void loop()
- {
- IO();
- // if we get a valid byte, transmit:
- if (Serial.available() > 0) {
- // get incoming byte:
- inByte = Serial.read();
- delay(10);
- Serial.print(total1);
- Serial.print(",");
- Serial.println(total2);
- }
- }
- void establishContact() {
- while (Serial.available() <= 0) {
- Serial.println("0,0"); // send an initial string
- IO();
- delay(300);
- }
- }
- void IO()
- {
- // read the analog inputs:
- total1 = cs1.capacitiveSensor(1000);
- total2 = cs2.capacitiveSensor(1000);
- tone(9, total1);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement