Pages: [1]   Go Down
Author Topic: I don't seem to understand C++  (Read 482 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

c++ stuff

I program in c and I cannot find any help with this problem in the C++ searches I have done.
I am accessing several DHT11 packages.  I am using the dht11 lib which seems to be written in C++

I am trying to use a function to process the serial data received from each of the packages.

my problem is I am trying to use a pointer to each package's data.
proper includes
Code:
#include <dht11.h>
I declared the objects

Code:
dht11 DHT11one;
dht11 DHT11two;

//then within the loop I will call each one and send it to:

Code:
void loop
{
  int chk1 = DHT11one.read(DHTPIN1);
  int chk2 = DHT11two.read(DHTPIN2);
  doTemp( &DHT11one);
  doTemp( &DHT11two);
}


void doTemp(dht11 *DHT11chk)
{
  float aTemp = *DHT11chk.temperature;
  do other stuff ... (store the temperature in a array, calc the average and send it to a display)
}

I guess I do not understand C++ but this does not work.  it tells me that DHT11chk is not declared within this scope

any and all help is appreciated!


Moderator edit: [code] [/code] tags added.
Author edit: clarify some information and correct a typo.
« Last Edit: January 13, 2013, 02:34:26 pm by RCork » Logged

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 206
Posts: 12849
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
proper includes

What does that mean?
Logged

Sydney, Australia
Online Online
Edison Member
*
Karma: 33
Posts: 1269
Big things come in large packages
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Even in C the parameter passed as a pointer would be declared as type *varname, not &varname.
Logged

Arduino libraries http://arduinocode.codeplex.com
Parola hardware & library http://parola.codeplex.com

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 216
Posts: 13664
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Try to get a copy of Kerningham and Ritchie C 2nd edition to learn some basics about C pointers

also a good learner = http://www.cplusplus.com/reference/cctype/
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Finland
Offline Offline
Jr. Member
**
Karma: 1
Posts: 84
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

This is where you create an instance of the class.
dht11 DHT11one;

This could do without the &-symbol, if you have defined the function to take a reference to the instance in.
doTemp( &DHT11one);

But, if it says dht11 has not been declared, you must not have included a header before you created the instance in the first place. And the type name is case-sensitive.

The pointer symbol here looks a little weird, but it does depend on what the temperature is returned as from the library. I assume it's a float anyways, and I think it would work better without the pointer symbol for what you are trying to do with it.
float aTemp = *DHT11.temperature;
Logged

Pages: [1]   Go Up
Jump to: