Last active
December 22, 2015 11:38
-
-
Save arielchuri/6466771 to your computer and use it in GitHub Desktop.
Using the CapSense data.
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_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