Pages: 1 [2] 3   Go Down
Author Topic: void value not ignored as it ought to be  (Read 1660 times)
0 Members and 1 Guest are viewing this topic.
Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 549
Posts: 46154
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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)); 
  }
}
Logged

Offline Offline
Full Member
***
Karma: 3
Posts: 188
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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)); 
  }
}

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);
Logged

for(i = 0, i < 820480075, i++){ Design(); Code(); delay(1000); } // hellowoo.com

Offline Offline
God Member
*****
Karma: 10
Posts: 651
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If Paul had that in code tags you'd see that there is a couple of array indexes there that aren't showing up.  Should look like:
Code:
for(int i = 0; i < numberOfSensors; i++)
   { // Down here where it belongs!
     cs_sensor[i] = new CapacitiveSensor(capSenseSend,sensorPin[i]);
   }

« Last Edit: April 05, 2013, 06:56:01 pm by Delta_G » Logged

Offline Offline
Full Member
***
Karma: 3
Posts: 188
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

If Paul had that in code tags you'd see that there is a couple of array indexes there that aren't showing up.  Should look like:
Code:
for(int i = 0; i < numberOfSensors; i++)
   { // Down here where it belongs!
     cs_sensor[i] = new CapacitiveSensor(capSenseSend,sensorPin[i]);
   }



Yes, tried this too. same error.

also tried:
Code:
cs_sensor[i] = new CapacitiveSensor(capSenseSend,sensorPin[i]);

but this gave error:  request for member 'setCurrentReading' in 'letters', which is of non-class type 'Letter [2]'
Logged

for(i = 0, i < 820480075, i++){ Design(); Code(); delay(1000); } // hellowoo.com

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 549
Posts: 46154
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Full Member
***
Karma: 3
Posts: 188
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

I did, its on the last page might have missed it, other than the changes you suggested. here it is again though just in case:

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, 9 };

//int allValues[numberOfSensors];

void setup(){
   Serial.begin(19200);
   delay(100);
   
   CapacitiveSensor *cs_sensor[numberOfSensors];
   
   for(int i = 0; i < numberOfSensors; i++){
     cs_sensor[i] = new CapacitiveSensor(capSenseSend,sensorPin);
   }
 
   // setup LEDs
   for(int i = 0; i < numberOfSensors; i++){
     pinMode(ledPin[i],OUTPUT);
     digitalWrite(ledPin[i], LOW); 
   }
   //cs_a.set_CS_AutocaL_Millis(0xFFFFFFFF);

   setSampleSize();   
}

void loop(){ 
    setSensorValue();
    checkIfButtonPressed();
    delay(100);
}

void setSampleSize(){
  for(int i = 0; i < numberOfSensors; i++){
    letters[i].setSampleAmount(5);
  }
}

void setSensorValue(){
  for(int i = 0; i < numberOfSensors; i++){
    letters.setCurrentReading(cs_sensor->capacitiveSensor(50)); 
  }
}

void checkIfButtonPressed(){
  for(int i = 0; i < numberOfSensors; i++){
    letters[i].checkIfIsOn(cs_sensor[i]);
  }
}

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);
}

Letters.h:
Code:
#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

Letter.ino:

Code:
#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;
  }
}
Logged

for(i = 0, i < 820480075, i++){ Design(); Code(); delay(1000); } // hellowoo.com

Offline Offline
God Member
*****
Karma: 10
Posts: 651
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Just follow exactly what the compiler told you.  The setSensorValue is missing an array index there.
Logged

Offline Offline
Full Member
***
Karma: 3
Posts: 188
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Just follow exactly what the compiler told you.  The setSensorValue is missing an array index there.

seems to stop way before that on: cs_sensor = new CapacitiveSensor(capSenseSend,sensorPin); with error:  error: invalid conversion from 'const byte*' to 'uint8_t'

I gave it an array index like so just now:

Code:
void setSensorValue(){
  for(int i = 0; i < numberOfSensors; i++){
    letters.setCurrentReading(cs_sensor[i]->capacitiveSensor(50));  
  }
}

same error. thats is the problem, no idea what the error means, and can't seem to find anything on google for it :/
Logged

for(i = 0, i < 820480075, i++){ Design(); Code(); delay(1000); } // hellowoo.com

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 549
Posts: 46154
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The array of pointers is local to setup(). Pretty useless there.
Logged

Offline Offline
Full Member
***
Karma: 3
Posts: 188
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

The array of pointers is local to setup(). Pretty useless there.

oh oops, seems moving the pointer outside the setup function doesn't seem to help either, same error:

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, 9 };

CapacitiveSensor *cs_sensor[numberOfSensors];
  
void setup(){
   Serial.begin(19200);
   delay(100);

   for(int i = 0; i < numberOfSensors; i++){
     cs_sensor[i] = new CapacitiveSensor(capSenseSend,sensorPin);
   }
  
   // setup LEDs
   for(int i = 0; i < numberOfSensors; i++){
     pinMode(ledPin[i],OUTPUT);
     digitalWrite(ledPin[i], LOW);  
   }

   setSampleSize();  
}

void loop(){  
    setSensorValue();
    checkIfButtonPressed();
    delay(100);
}

void setSampleSize(){
  for(int i = 0; i < numberOfSensors; i++){
    letters[i].setSampleAmount(5);
  }
}

void setSensorValue(){
  for(int i = 0; i < numberOfSensors; i++){
    letters.setCurrentReading(cs_sensor[i]->capacitiveSensor(50));  
  }
}

void checkIfButtonPressed(){
  for(int i = 0; i < numberOfSensors; i++){
    letters[i].checkIfIsOn(cs_sensor[i]);
  }
}

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);
}

earlier I mentioned I set that line with the error to: cs_sensor = new CapacitiveSensor(capSenseSend,sensorPin);
which seems like what it is suppose to be, however farther down I get:

error:  request for member 'setCurrentReading' in 'letters', which is of non-class type 'Letter [2]'
for:
Code:
letters.setCurrentReading(cs_sensor[i]->capacitiveSensor(50));

so I am not sure if this is correct thing to do.
« Last Edit: April 05, 2013, 08:02:00 pm by hilukasz » Logged

for(i = 0, i < 820480075, i++){ Design(); Code(); delay(1000); } // hellowoo.com

Offline Offline
God Member
*****
Karma: 10
Posts: 651
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Here are two more illegal conversions from byte pointer to uint8_t

Code:
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);
}

Go through your code and fix all these.  If you are going to use the array you'll need to put the index with it.  Get all that fixed, and post us new code to look at. 
Logged

Offline Offline
Full Member
***
Karma: 3
Posts: 188
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Here are two more illegal conversions from byte pointer to uint8_t

Code:
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);
}

Go through your code and fix all these.  If you are going to use the array you'll need to put the index with it.  Get all that fixed, and post us new code to look at. 

I would fix it if I knew what was wrong to be honest. this section of code has compiled fine in the past, not sure what would be wrong with it. I don't even know how to look up what that "illegal conversions from byte pointer to uint8_t" error is, google isn't giving me anything.
Logged

for(i = 0, i < 820480075, i++){ Design(); Code(); delay(1000); } // hellowoo.com

Offline Offline
God Member
*****
Karma: 10
Posts: 651
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Googling for pointer and c++ gives a ton of stuff.  Many many tutorials that explain what a pointer is.  Once you know that it should be obvious that you can't convert one to an intended type. 

But even without that, I told you how to fix it.  pin numbers is an array.  You're using it without an index.  That won't work. 
Logged

Offline Offline
God Member
*****
Karma: 10
Posts: 651
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
Serial.print(allValues[0]); Serial.print(" , "); Serial.print(allValues[1]); delay(10);

And I'm betting this line will give you an allValues not declared in this scope error.  I don't see it declared anywhere anyway.

EDIT:  Found it in the previous code, but it was commented out there. 
Logged

Offline Offline
Full Member
***
Karma: 3
Posts: 188
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Googling for pointer and c++ gives a ton of stuff.  Many many tutorials that explain what a pointer is.  Once you know that it should be obvious that you can't convert one to an intended type. 

But even without that, I told you how to fix it.  pin numbers is an array.  You're using it without an index.  That won't work. 

maybe I am misunderstanding but pinNumber is an int, not an array. are you looking at ledPin or sensorPin maybe? those are different and in fact an array.
Logged

for(i = 0, i < 820480075, i++){ Design(); Code(); delay(1000); } // hellowoo.com

Pages: 1 [2] 3   Go Up
Jump to: