Created
February 11, 2014 20:41
-
-
Save arielchuri/8943653 to your computer and use it in GitHub Desktop.
Code to see the value from the touch sensor.
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> //Load the capSense Library which the touch sensor uses. | |
CapacitiveSensor cs_4_2 = CapacitiveSensor(4,2); // Set up the touch sensor on pins 4 and 2. | |
long capSense; // A variable to store the value from the touch sensor. | |
int ledPins[] = { | |
11, 10, 9, 6, 5, 3 }; | |
int pinCount = 6; | |
int lightPin = A0; | |
int lightValue = 0; | |
int aLED = 13; | |
boolean aLEDstate; | |
void setup() { | |
Serial.begin(9600); | |
pinMode(aLED, OUTPUT); | |
for (int thisPin = 0; thisPin < pinCount; thisPin++) { | |
pinMode(ledPins[thisPin], OUTPUT); | |
} | |
startUp(); | |
} | |
//===============LOOP================// | |
void loop() { | |
long start = millis(); // Start a timer which the touch sensor needs. | |
capSense = cs_4_2.capacitiveSensor(30); // Read the touch sensor and store the value. | |
lightValue = analogRead(lightPin); | |
monitor(); | |
} | |
//==============ENDLOOP==============// | |
void startUp() { | |
Serial.println("\n"); | |
for (int thisPin = 0; thisPin < pinCount; thisPin++) { | |
digitalWrite(ledPins[thisPin], HIGH); | |
delay(30); | |
digitalWrite(ledPins[thisPin], LOW); | |
Serial.print(thisPin); | |
} | |
for (int thisPin = pinCount - 1; thisPin >= 0; thisPin--) { | |
digitalWrite(ledPins[thisPin], HIGH); | |
delay(30); | |
digitalWrite(ledPins[thisPin], LOW); | |
Serial.print(thisPin); | |
} | |
Serial.println(" STARTUP!"); | |
} | |
void monitor() { | |
Serial.print("light = "); | |
Serial.print(lightValue); | |
Serial.print("\t touch = "); // The "\t" character is a tab space to clean up the read out. | |
Serial.println(capSense); | |
digitalWrite(aLED, aLEDstate); | |
aLEDstate = !aLEDstate; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment