The function, as you pointed out, does not return a value. Instead of accepting that, and ignoring it, you try to assign it to a variable. Why?
trying to set the variable currentReading in the class to that capacitive value I am passing. maybe I am going about this wrong? In JS I think it would be something more like Letter.currentReading = cs_a.capacitiveSensor(50);
I might be going about it wrong in C++ though, I thought you can't directly set variables like that and have to use a method to do so.
The function name, including set, should give you a clue that it is NOT reading anything. The class has a function with a similar name but with get instead of set. Get methods read. Why are you not using getCurrentReading() to get the current reading?
Edit: I reread what you are trying to do. I don't understand it. You can use setCurrentReading() to set a value, but it doesn't return anything. You can use getCurrentReading() to get the value, and it does return something.
Only when a function returns a value can the value be stored in a variable or passed to another function.
Normally, when using get and set functions, the setter doesn't return anything - there's no point - you already know what the value is because you're passing it in. You could change the setter to return the value it's passed and then use it to populate aValue in the manner you're trying. However, why bother:
int calSenseA = cs_a.capacitiveSensor(50);
aValue = letters[0].setCurrentReading(calSenseA);
You already have the value in another variable - calSenseA . Use that in your serial print.
PaulS:
The function name, including set, should give you a clue that it is NOT reading anything. The class has a function with a similar name but with get instead of set. Get methods read. Why are you not using getCurrentReading() to get the current reading?
Edit: I reread what you are trying to do. I don't understand it. You can use setCurrentReading() to set a value, but it doesn't return anything. You can use getCurrentReading() to get the value, and it does return something.
Only when a function returns a value can the value be stored in a variable or passed to another function.
that is what I am saying, the setCurrentReading should set the value, but it does not. that is the line that throws the error, the setCurrentReading is the method that is throwing the error in the main ino file.
I guess I just need to know how to set currentReading in the class using calSenseA variable in the main ino file, not sure how to go about that. if that makes sense? apparently how I am doing it now isnt working. I thought that public variables can be set in this way.
wildbill:
Normally, when using get and set functions, the setter doesn't return anything - there's no point - you already know what the value is because you're passing it in. You could change the setter to return the value it's passed and then use it to populate aValue in the manner you're trying. However, why bother:
int calSenseA = cs_a.capacitiveSensor(50);
aValue = letters[0].setCurrentReading(calSenseA);
You already have the value in another variable - calSenseA . Use that in your serial print.
I need to set the variable, not print it. It needs to be stored in the class is all. eventually I will read it, but I am getting the error on this line implying I am doing something wrong here.
seem to have a new problem this one really is stumping me even after reading about how to use these, since its using a library it makes it confusing. Seems like capacitive sensor library makes you set the objects value to a function in the library, so I am not sure how to make this work.
I need to populate an array of objects I would expect it to work how I have it here in the setup function:
CapacitiveSensor cs_sensor[numberOfSensors];
for(int i = 0; i < numberOfSensors; i++){
cs_sensor[i] = CapacitiveSensor(capSenseSend,sensorPin[i]);
}
so I can later set the current reading using this in the loop:
void setSensorValue(){
for(int i = 0; i < numberOfSensors; i++){
letters[i].setCurrentReading(cs_sensor[i].capacitiveSensor(50));
}
}
I don't know how many cap sensors you are trying to create, so you need to make sure that the number of entries is correct.
Or, you can use pointers and the new operator.
ah, ok. I would prefer to use pointers since speed is an issue and it has been on to do list. I have never used pointers before though. Is there anything in particular in this context that I should try to look up to read more on it? I am not even sure what to search. "using pointers to populate objects...?"
number of sensors is set by variable: numberOfSensors
I would prefer to use a loop so I can change this as I go, I need to prototype it as I go, so I will start with 4 sensors then 8 then 20, etc.
I would prefer to use pointers since speed is an issue
Pointers are not necessarily faster than other means of data access.
In this case, you would make some minor changes:
CapacitiveSensor *cs_sensor[numberOfSensors];
for(int i = 0; i < numberOfSensors; i++)
{ // Down here where it belongs!
cs_sensor = new CapacitiveSensor(capSenseSend,sensorPin*);* * }* void setSensorValue() { // Down here where it belongs! * for(int i = 0; i < numberOfSensors; i++)* * { // Down here where it belongs!* letters.setCurrentReading(cs_sensor*->capacitiveSensor(50)); _ } }*_
I would prefer to use pointers since speed is an issue
Pointers are not necessarily faster than other means of data access.
In this case, you would make some minor changes:
CapacitiveSensor *cs_sensor[numberOfSensors];
for(int i = 0; i < numberOfSensors; i++)
{ // Down here where it belongs!
cs_sensor = new CapacitiveSensor(capSenseSend,sensorPin*);* * }* void setSensorValue() { // Down here where it belongs! * for(int i = 0; i < numberOfSensors; i++)* * { // Down here where it belongs!* letters.setCurrentReading(cs_sensor*->capacitiveSensor(50)); _ } } [/quote]_ hmm this seems to throw an error that I can't find much info on: invalid conversion from 'const byte' to 'uint8_t' for the line cs_sensor = new CapacitiveSensor(capSenseSend,sensorPin);
You need to post your current code, so that we can see that you made all the required changes, correctly. And so we can replicate (and solve) the problem more easily.