Hi, sorry to message directly but ran some of your post and you look like you know your stuff.
i'm doing a project based on the capacitive sensor method. the code will work fine as standard, but when its with my added extras it doesnt work but it compiles. The other thing is that the its printing to the serial at 3.4 seconds, do you know why this might be.
here's the code.
#include <CapacitiveSensor.h>
#include <Servo.h>
Servo Mech;
int pos = 0;
/*
- CapitiveSense Library Demo Sketc * Paul Badger 2008
-
- Uses a high value resistor e.g. 10M between send pin and receive pin
6 * Resistor effects sensitivity, experiment with values, 50K - 50M. Larger resistor values yield larger sensor values.
- Uses a high value resistor e.g. 10M between send pin and receive pin
-
- Receive pin is the sensor pin - try different amounts of foil/metal on this pin
- */
CapacitiveSensor cs_4_2 = CapacitiveSensor(4,2); // 10M resistor between pins 4 & 2, pin 2 is sensor pin, add a wire and or foil if desired
CapacitiveSensor cs_4_6 = CapacitiveSensor(4,6); // dnt need this
CapacitiveSensor cs_4_8 = CapacitiveSensor(4,8); // 10M resistor between pins 4 & 8, pin 8 is sensor pin, add a wire and or foil
int light = 13;
int yellow = 12; //dnt need this
int power = 11;
int fans = 5;
boolean status_light = LOW, status_light_prev = LOW;
boolean status_yellow = LOW, status_yellow_prev = LOW; // dnt need this
boolean status_power = LOW, status_power_prev = LOW;
void setup()
{
cs_4_2.set_CS_AutocaL_Millis(0xFFFFFFFF); // turn off autocalibrate on channel 1 - just as an example
Serial.begin(9600);
Mech.attach(9);
pinMode(light, OUTPUT);
pinMode(yellow, OUTPUT); // dnt need this
pinMode(power, OUTPUT);
pinMode(fans, OUTPUT);
}
void loop()
{
long start = millis();
long total1 = cs_4_2.capacitiveSensor(30); // to power pin 11
long total2 = cs_4_6.capacitiveSensor(30); // dnt need this
long total3 = cs_4_8.capacitiveSensor(30); // to light
Serial.print(millis() - start); // check on performance in milliseconds
Serial.print("\t"); // tab character for debug windown spacing
Serial.print(total1); // print sensor output 1
Serial.print("\t\t\t");
Serial.print(total2); // print sensor output 2
Serial.print("\t\t\t");
Serial.println(total3); // print sensor output 3
delay(100); // arbitrary delay to limit data to serial port
if (total1 > 200)
status_light = !status_light;
Serial.print("\tstatus_light = ");
Serial.print(status_light);
Serial.print("\t");
if (status_light)
Mech.write(20);
else
Mech.write(160);
delay(600);
if (status_light)
digitalWrite(light, HIGH);
else
digitalWrite(light, LOW);
if (total2 > 200) // dnt need this
status_yellow = !status_yellow;
Serial.print("status_yellow = ");
Serial.print(status_yellow);
Serial.print("\t");
if (status_yellow)
digitalWrite(yellow, HIGH);
else
digitalWrite(yellow, LOW);
if (total3 > 200)
status_power = !status_power;
Serial.print("status_power = ");
Serial.println(status_power);
if (status_power)
digitalWrite(power, HIGH);
else
digitalWrite(power, LOW);
if (status_power)
if (status_power)
digitalWrite(fans, HIGH);
else
digitalWrite(fans, LOW);
}
thank you for your help, thank you