Untitled

mail@pastecode.io avatar
unknown
plain_text
6 months ago
1.1 kB
1
Indexable
Never
/*******************************************************************************
* Capacitive Sensing for Touch and Proximity
*
* Prints the values of a capacitive sensor.
*
*******************************************************************************/
#include <CapacitiveSensor.h>

double analog_touch;

int sender = 25;

int touch_pin_1 = 14;

int samples_touch = 10;

bool processingGo = false;

int value = 0;
int mapped = 0;
int reading = 0;
CapacitiveSensor sensor1 = CapacitiveSensor(sender, touch_pin_1);

void setup() {
  Serial.begin(9600);
}

void loop() {
  value = 0;
  for (int i = 0; i < 2000; i++) {
    reading = analogRead(touch_pin_1);
    if (reading > value) {
      value = reading;
    }
  }
  //mapped = map(value, 530, 900, 180, 90);


  delay(20);
  printValues();
  sendToProcessing();
}

void printValues() {
  if (!processingGo) {
    Serial.print(value);
    Serial.print(" | ");
    Serial.println(mapped);
  }
}

void sendToProcessing() {
  if (processingGo) {
    Serial.print(value);
    Serial.print(";");
  }
}
Leave a Comment