Hi all,
I'm making some pressure sensors using the CapSense library (Arduino Playground - HomePage), and while I am able to get it to work for a few inputs, I am currently trying to think of a way to code it quickly for a large number of inputs.
Here is the beginning of the code for the script I know works:
CapacitiveSensor cs_4_2 = CapacitiveSensor(4,2); // 10 megohm resistor between pins 4 & 2, pin 2 is sensor pin, add wire, foil
CapacitiveSensor cs_4_6 = CapacitiveSensor(4,6); // 10 megohm resistor between pins 4 & 6, pin 6 is sensor pin, add wire, foil
CapacitiveSensor cs_4_8 = CapacitiveSensor(4,8); // 10 megohm resistor between pins 4 & 8, pin 8 is sensor pin, add wire, foil
CapacitiveSensor cs_4_10 = CapacitiveSensor(4,10); // 10 megohm resistor between pins 4 & 10, pin 10 is sensor pin, add wire, foil
However, if I were to do this for say 50 inputs, it would get quite tedious, and I have to repeat this a few times in other bits of the code as well. So I tried to put this in the void setup() bit of the code, but keep getting the error: variable-sized object 'capS' may not be initialized even though I thought I initialised it at the top.
void setup()
{
int capS[4];
for (int i = 3; i < 7; i++){
//capS[i];
CapacitiveSensor capS[i] = CapacitiveSensor(2,i);// 10 megohm resistor between pins 4 & 2, pin 2 is sensor pin, add wire, foil
}
//capS[3].set_CS_AutocaL_Millis(0xFFFFFFFF); // turn off autocalibrate on channel 1 - just as an example
Serial.begin(9600);
}
Also I was wondering, why can you not put a for loop in the initialisation bit at the top of the code? I get error: expected unqualified-id before 'for' if I do.
Thanks,
Raunaq
EDIT: sorry just added something to the code I left out earlier (the [4] after the capS).