Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Using the CapSense data.
#include <CapacitiveSensor.h>
CapacitiveSensor cs_4_2 = CapacitiveSensor(4,2);
int led = 13;
int led2 = 11;
byte fade;
long timer;
long previousTimer;
int ledState = LOW;
int sensorPin = A0;
int sensorValue = 0;
void setup() {
pinMode(led, OUTPUT);
pinMode(led2, OUTPUT);
Serial.begin(9600);
}
void loop() {
//CapSense Section
long start = millis();
long total1 = cs_4_2.capacitiveSensor(30);
Serial.print(millis() - start); // check on performance in milliseconds
Serial.print("\t"); // tab character for debug windown spacing
Serial.println(total1); // print sensor output 1
delay(10); // arbitrary delay to limit data to serial port
// Light Sensor Section
sensorValue = analogRead(sensorPin);
if ( sensorValue <= 400 ) {
ledState = HIGH;
}
else {
ledState = LOW;
}
// Light LEDs Section
digitalWrite(led, ledState); // turn the LED on (HIGH is the voltage level)
analogWrite(led2, total1*2);
//fade++;
/*
Serial.print("timer= ");
Serial.print(timer);
Serial.print("\t previousTimer= ") ;
Serial.print(previousTimer);
Serial.print("\t fade= ");
Serial.println(fade);
*/
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment