-1

I was compling my code in Arduino and suddenly I got this error:

 core.a(main.cpp.o): In function `main':
 D:\Personal\Arduino\arduino-1.0.4-windows\arduino-  1.0.4\hardware\arduino\cores\arduino/main.cpp:11: undefined reference to `setup'
 D:\Personal\Arduino\arduino-1.0.4-windows\arduino-1.0.4\hardware\arduino\cores\arduino/main.cpp:14: undefined reference to `loop'

I have no idea what that means. Here's my code:

#ifndef dht_h
#define dht_h

#if ARDUINO < 100
    #include <WProgram.h>
#else
    #include <Arduino.h>
#endif

#define DHT_LIB_VERSION "0.1.05"

#define DHTLIB_OK                0
#define DHTLIB_ERROR_CHECKSUM   -1
#define DHTLIB_ERROR_TIMEOUT    -2
#define DHTLIB_INVALID_VALUE  -999
#include <dht.h>

#define TIMEOUT 10000

class dht
{
    public:
        int read22(uint8_t pin);
            double humidity;
            double temperature;

    private:
        uint8_t bits[5];  // Buffer to receive data
        int read(uint8_t pin);
};
#endif


// return values:
// DHTLIB_OK
// DHTLIB_ERROR_CHECKSUM
// DHTLIB_ERROR_TIMEOUT
int dht::read22(uint8_t pin)
{
    // READ VALUES
    int rv = read(pin);
    if (rv != DHTLIB_OK)
    {
        humidity    = DHTLIB_INVALID_VALUE;  // Invalid value, or is NaN prefered?
        temperature = DHTLIB_INVALID_VALUE;  // Invalid value
        return rv;
    }

    // CONVERT AND STORE
    humidity    = word(bits[0], bits[1]) * 0.1;

    if (bits[2] & 0x80) // negative temperature
    {
        temperature = word(bits[2]&0x7F, bits[3]) * 0.1;
        temperature *= -1.0;
    }
    else
    {
        temperature = word(bits[2], bits[3]) * 0.1;
    }

    // TEST CHECKSUM
    uint8_t sum = bits[0] + bits[1] + bits[2] + bits[3];
    if (bits[4] != sum) return DHTLIB_ERROR_CHECKSUM;

    return DHTLIB_OK;
}

//Private
// return values:
// DHTLIB_OK
// DHTLIB_ERROR_TIMEOUT
int dht::read(uint8_t pin)
{
    // INIT BUFFERVAR TO RECEIVE DATA
    uint8_t cnt = 7;
    uint8_t idx = 0;

    // EMPTY BUFFER
    for (int i=0; i< 5; i++) bits[i] = 0;

    // REQUEST SAMPLE
    pinMode(pin, OUTPUT);
    digitalWrite(pin, LOW);
    delay(20);
    digitalWrite(pin, HIGH);
    delayMicroseconds(40);
    pinMode(pin, INPUT);

    // GET ACKNOWLEDGE or TIMEOUT
    unsigned int loopCnt = TIMEOUT;
    while(digitalRead(pin) == LOW)
            if (loopCnt-- == 0) return DHTLIB_ERROR_TIMEOUT;

    loopCnt = TIMEOUT;
    while(digitalRead(pin) == HIGH)
            if (loopCnt-- == 0) return DHTLIB_ERROR_TIMEOUT;

    // READ THE OUTPUT - 40 BITS => 5 BYTES
    for (int i=0; i<40; i++)
    {
        loopCnt = TIMEOUT;
        while(digitalRead(pin) == LOW)
            if (loopCnt-- == 0)
                return DHTLIB_ERROR_TIMEOUT;

        unsigned long t = micros();

        loopCnt = TIMEOUT;
        while(digitalRead(pin) == HIGH)
            if (loopCnt-- == 0)
                return DHTLIB_ERROR_TIMEOUT;

        if ((micros() - t) > 40)
            bits[idx] |= (1 << cnt);
        if (cnt == 0) // Next byte?
        {
            cnt = 7;
            idx++;
        }
        else
            cnt--;
    }
    return DHTLIB_OK;
}

What do I need to do to fix this code?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Artemis F
  • 72
  • 3
  • 4
  • 19
  • the code you're giving is irrelevant, but the code from your previous [question](http://stackoverflow.com/questions/17484043/what-does-type-error-mean-in-arduino/17485021) is. – zmo Jul 05 '13 at 11:46
  • How do you compile your sketch? are you using the Arduino IDE? Do you click on `verify` or `upload` when you want to compile your sketch **on the window where the sketch is loaded**? A "sketch" is the file that has the `loop()` and `setup()` functions (cf your previous question). – zmo Jul 05 '13 at 11:48
  • and do you click verify on the window that contains `setup()` and `loop()`? – zmo Jul 05 '13 at 11:59
  • ok, then you did not solve your previous problem, and just replaced a problem by another. Please delete this question, as it is neither useful for you or future readers of the site. – zmo Jul 05 '13 at 12:53

1 Answers1

0

Every Arduino Programm needs the functions setup() and loop(), you have neither of them.

You should probably check this out.

You should add them to your main file(usually the first you created in the IDE).

Dahaka
  • 507
  • 1
  • 4
  • 14
  • It is true that every ardiuno program needs a setup() and a loop() function, But not every file. I fear that the asker of this question will attempted to add a setup() and a loop() to this dht object, rather then add the setup() and loop() to his main file. – John b Jul 08 '13 at 13:32
  • @John b, I added this code to the library file of dht and it worked. Thanks! – Artemis F Jul 09 '13 at 05:55