getting the error of "void value not ignored as it ought to be"
the culprit is this line of code in the main cpp:
aValue = letters[0].setCurrentReading(calSenseA);
the code:
#include <CapacitiveSensor.h>
#include "Letter.h"
const byte capSenseSend = 2;
const byte numberOfSensors = 2;
Letter letters[numberOfSensors]; // a-z
const byte sensorPin[] = { 22, 23 };
const byte ledPin[] = { 8 };
int allValues[numberOfSensors];
int aValue, bValue;
CapacitiveSensor cs_a = CapacitiveSensor(capSenseSend,sensorPin[0]);
CapacitiveSensor cs_b = CapacitiveSensor(capSenseSend,sensorPin[1]);
void setup(){
// setup LEDs
for(int i = 0; i < numberOfSensors; i++){
pinMode(ledPin[i],OUTPUT);
digitalWrite(ledPin[i], LOW);
}
cs_a.set_CS_AutocaL_Millis(0xFFFFFFFF);
delay(100);
Serial.begin(19200);
delay(100);
letters[0].setSampleAmount(5);
letters[1].setSampleAmount(5);
}
void loop(){
int calSenseA = cs_a.capacitiveSensor(50);
aValue = letters[0].setCurrentReading(calSenseA);
bValue = (int)letters[1].setCurrentReading((int)cs_b.capacitiveSensor(50));
Serial.print(" A : "); Serial.print(aValue); Serial.print(" , "); Serial.println(bValue);
int allValues[] = { aValue, bValue };
checkIfisOn(allValues);
delay(100);
}
void fadeLedIn(int pinNumber){
for(int j = 0; j <= 255; j+=10){
analogWrite(pinNumber,j);
delay(10);
}
}
void fadeLedOut(int pinNumber){
for(int j = 255; j >= 0; j-=10){
analogWrite(pinNumber,j);
delay(10);
}
digitalWrite(pinNumber, LOW);
}
void sendSerialData(int buttonTouched){
delay(10);
Serial.print("Data,");
delay(10);
Serial.print(buttonTouched);
delay(10);
Serial.print(",");
Serial.print("sensors : ");
Serial.print(allValues[0]); Serial.print(" , "); Serial.print(allValues[1]);
delay(10);
Serial.print("\n");
delay(10);
}
header file:
//#include "Arduino.h"
#ifndef LETTER_H
#define LETTER_H
class Letter {
public:
Letter();
double getAverage(int sample);
void setSampleAmount(int changeSampleTo);
void setLastReading(int theLastReading);
void setCurrentReading(int theCurrentReading);
void checkIfisOn(int curentSensorValue[]);
int getCurrentReading();
int getLastReading();
int aValue;
int lastReading;
int currentReading;
private:
int _sampleAmount;
double _tempAverage,
_capacitiveAverage;
double _runningAverage[100];
};
#endif
definitions:
#include "Letter.h" // "" for files within same folder as sketch...?
Letter::Letter() {
_sampleAmount = 5;
_tempAverage = 0;
_capacitiveAverage = 0;
lastReading = 0;
currentReading = 0;
//long _runningAverage[_sampleAmount];
};
void Letter::setSampleAmount(int changeSampleTo){
_sampleAmount = changeSampleTo;
};
void Letter::setLastReading(int theLastReading){
lastReading = theLastReading;
}
void Letter::setCurrentReading(int theCurrentReading){
currentReading = theCurrentReading;
}
int Letter::getLastReading(){
return lastReading;
}
int Letter::getCurrentReading(){
return currentReading
}
double Letter::getAverage(int sample) {
for(int i = 0; i < _sampleAmount; i++){
_runningAverage[i] = sample;
}
// reset _tempAverage
_tempAverage = 0;
// add all the samples up
for(int i = 0; i < _sampleAmount; i++){
_tempAverage += _runningAverage[i];
}
// divide by number of samples to get average
_capacitiveAverage = _tempAverage/_sampleAmount;
return _capacitiveAverage;
};
void Letter::checkIfisOn(){
boolean firstTime = true;
int firstRelease = 0;
const int threshold = 55;
int differenceReading = curentSensorValue-lastReading;
if(differenceReading > threshold && firstTime == true){
sendSerialData(i);
fadeLedIn(ledPin[i]);
if((currentReading-lastReading) < threshold){
digitalWrite(ledPin[i], LOW);
fadeLedOut(ledPin[i]);}
lastReading[i] = currentReading[i];
firstTime = false;
}
}
I am a little confused because the method isn't returning a value, it is simply setting a value so not sure why I would get this error.