Last active
August 29, 2015 14:24
-
-
Save dyadica/0195fc01473347b58390 to your computer and use it in GitHub Desktop.
Example code for the IOST Capacitive Sensing Library breakout
This file contains hidden or 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> | |
// Initialise all of our cap sensors. Each shares the | |
// 12 pin. | |
CapacitiveSensor caps[] = | |
{ | |
CapacitiveSensor(12,2), | |
CapacitiveSensor(12,3), | |
CapacitiveSensor(12,4), | |
CapacitiveSensor(12,5), | |
CapacitiveSensor(12,6), | |
CapacitiveSensor(12,7) | |
}; | |
// Set a threshold value for which is used to | |
// register a trigger event. | |
int threshold = 500; | |
// Set a long array to store the cap values. | |
long values[] = | |
{ | |
0,0,0,0,0,0 | |
}; | |
// Set ref for an led that can be used to show | |
// that the threshold has been exceeded. | |
int ledPin = 13; | |
void setup() | |
{ | |
// Pause to allow for boot of an xbee or BT if connected | |
// delay(6000); | |
for(int i=0; i < 6; i++) | |
{ | |
// caps[i].set_CS_AutocaL_Millis(0xFFFFFFFF); | |
} | |
// Set the led pin as an output | |
pinMode(ledPin, OUTPUT); | |
// Set the led to off | |
digitalWrite(ledPin, LOW); | |
// Initialise the serial | |
Serial.begin(9600); | |
} | |
void loop() | |
{ | |
// Loop through the list of sensors and read the | |
// value of each sensor. | |
for(int i=0; i < 6; i++) | |
{ | |
values[i] = caps[i].capacitiveSensor(30); | |
// Print the value of the sensor to serial | |
Serial.print(values[i]); | |
// If we are at the final sensor in the list | |
// do a print line, otherwise print a comma. | |
if(i != 5) { Serial.print(","); } | |
else { Serial.println(); } | |
} | |
// Turn off the led | |
digitalWrite(ledPin, LOW); | |
// Loop through the list of sensor values and if | |
// one or more of the values is greater than the | |
// threshold re-light the led | |
for(int i=0; i < 6; i++) | |
{ | |
if(values[i] > threshold) | |
{ | |
digitalWrite(ledPin, HIGH); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment