极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 14773|回复: 3

member function declared in class 报错

[复制链接]
发表于 2012-5-15 17:41:07 | 显示全部楼层 |阅读模式
请问这种情况是啥回事??
no 'float MAX6675::read_temp()' member function declared in class 'MAX6675'

但是类里已经定义了
  1. #ifndef MAX6675_h
  2. #define MAX6675_h

  3. #include "WProgram.h"

  4. class MAX6675
  5. {
  6.   public:
  7.     MAX6675(int CS_pin, int SO_pin, int SCK_pin, int units);
  8.     float read_temp();
  9.   private:
  10.     int _CS_pin;
  11.     int _SO_pin;
  12.     int _SCK_pin;
  13.     int _units;
  14.         int chip_read( int CS_pin, int &error_tc );
  15. };

  16. #endif
复制代码
Cpp文件
  1. #include <WProgram.h>
  2. #include <MAX6675.h>

  3. MAX6675::MAX6675(int CS_pin, int SO_pin, int SCK_pin, int units)
  4. {
  5.   pinMode(CS_pin, OUTPUT);
  6.   pinMode(SO_pin, INPUT);
  7.   pinMode(SCK_pin, OUTPUT);
  8.   
  9.   digitalWrite(CS_pin, HIGH);
  10.   
  11.   _CS_pin = CS_pin;
  12.   _SO_pin = SO_pin;
  13.   _SCK_pin = SCK_pin;
  14.   _units = units;
  15. }

  16. float MAX6675::read_temp()
  17. {
  18.         int value = 0;
  19.         int error_tc = 0;
  20.         float temp = 0.0;
  21.        
  22.      digitalWrite(_CS_pin,LOW);                                 
  23.     delay(2);
  24.     digitalWrite(_CS_pin,HIGH);
  25.     delay(220);

  26.        
  27.         digitalWrite(_CS_pin,LOW);
  28.        
  29.         digitalWrite(_SCK_pin,HIGH);
  30.         delay(1);
  31.         digitalWrite(_SCK_pin,LOW);

  32.         for (int i=11; i>=0; i--) {
  33.                 digitalWrite(_SCK_pin,HIGH);
  34.                 value += digitalRead(_SO_pin) << i;
  35.                 digitalWrite(_SCK_pin,LOW);
  36.         }
  37.         digitalWrite(_SCK_pin,HIGH);
  38.         error_tc = digitalRead(_SO_pin);
  39.         digitalWrite(_SCK_pin,LOW);

  40.         for (int i=1; i>=0; i--) {
  41.                 digitalWrite(_SCK_pin,HIGH);
  42.                 delay(1);
  43.                 digitalWrite(_SCK_pin,LOW);
  44.         }

  45.         // Disable Device
  46.         digitalWrite(_CS_pin, HIGH);
  47.   
  48.         if(_units == 2) {
  49.                 temp = (value*0.25) * 9.0/5.0 + 32.0;
  50.         } else if(_units == 1) {
  51.                 temp = (value*0.25);
  52.         } else {
  53.                 temp = value;
  54.         }
  55.   
  56. if(error_tc != 0) {
  57.                 return -_CS_pin;
  58.         } else {
  59.                 return temp;
  60.         }
  61. }
复制代码
回复

使用道具 举报

发表于 2012-5-15 19:57:35 | 显示全部楼层
额。。。。有完整的库和代码吗。。。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2012-5-15 23:02:34 | 显示全部楼层

已经是完整的库了,下面的是程序
  1. #include <MAX6675.h>

  2. int LED1 = 9;             // Status LED Pin
  3. int CS = 10;             // CS pin on MAX6675
  4. int SO = 12;              // SO pin of MAX6675
  5. int SCK = 13;             // SCK pin of MAX6675
  6. int units = 2;            // Units to readout temp (0 = raw, 1 = &#730;C, 2 = &#730;F)
  7. float temperature = 0.0;  // Temperature output variable


  8. // Initialize the MAX6675 Library for our chip
  9. MAX6675 temp(CS,SO,SCK,units);


  10. // Setup Serial output and LED Pin  
  11. // MAX6675 Library already sets pin modes for MAX6675 chip!
  12. void setup() {
  13.   Serial.begin(9600);
  14.   pinMode(LED1, OUTPUT);
  15. }

  16. void loop() {
  17.         // Read the temp from the MAX6675
  18.         temperature = temp.read_temp();

  19.         if(temperature < 0) {                  
  20.                 // If there is an error with the TC, temperature will be < 0
  21.                 Serial.print("Thermocouple Error on CS");
  22.                 Serial.println( temperature );
  23.                 digitalWrite(LED1, HIGH);
  24.         } else {
  25.                 Serial.print("Current Temperature: ");
  26.                 Serial.println( temperature );
  27.                 digitalWrite(LED1, LOW);
  28.         }

  29.         // Wait one second before reading again
  30.         delay(1000);       
  31. }
复制代码
回复 支持 反对

使用道具 举报

发表于 2013-5-9 16:55:15 | 显示全部楼层
你的库文件放到了自带库的目录下了????
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则 需要先绑定手机号

Archiver|联系我们|极客工坊

GMT+8, 2024-5-2 18:04 , Processed in 0.064114 second(s), 19 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表