2

I have fair experience with C/C++ so I decided to have a go at writing my first simple Arduino library. I wrote the code which seems to be fine to me except that it keeps complaining about the header file not found during compilation:

/home/me/sketchbook/libraries/SegDisplay/SegDisplay.cpp:1:24: fatal error: SegDispaly.h: No such file or directory
 #include "SegDispaly.h"
                        ^
compilation terminated.

I have the library located in my sketch folder under the name "SegDisplay":

/home/me/sketchbook/libraries/
└── SegDisplay
    ├── examples
    ├── keywords.txt
    ├── README.md
    ├── SegDisplay.cpp
    └── SegDisplay.h

and here's the code:

SegDisplay.h:

#ifndef _SEVEN_SEG_H_
#define _SEVEN_SEG_H_

#include <math.h>

#if defined(ARDUINO) && (ARDUINO >= 100)
#include <Arduino.h>
#else
#include <WProgram.h>
#endif

class SegDisplay
{
public:
    SegDisplay (int clockPin, int latchPin, int dataPin, int digitPins[4]);
    void display (double value);

private:
    const int digitPins[4];
    const int clockPin;
    const int latchPin;
    const int dataPin;
    const byte digit[10] = //seven segment digits in bits
    {
        B00111111, //0
        B00000110, //1
        B01011011, //2
        B01001111, //3
        B01100110, //4
        B01101101, //5
        B01111101, //6
        B00000111, //7
        B01111111, //8
        B01101111  //9
    };
    int digitBuffer[4];

    void setRegisterData (byte data);
    void clearRegister();
    void clearDisplay();
    void updateDisplay();
};

#endif

SegDisplay.cpp:

#include "SegDispaly.h"

SegDisplay::SegDisplay (int a, int b, int c, int d[4]):
    clockPin (a), latchPin (b), dataPin (c), digitPins (d), digitBuffer ({0})
{
    for (int i = 0; i < 4; i++)
    {
        pinMode (digitPins[i], OUTPUT);
        digitalWrite (digitPins[i], HIGH);
    }
    pinMode (latchPin, OUTPUT);
    pinMode (clockPin, OUTPUT);
    pinMode (dataPin, OUTPUT);  
}

void SegDispaly::setRegisterData (byte data)
{
    digitalWrite (latchPin, LOW);  
    shiftOut (dataPin, clockPin, MSBFIRST, data);
    digitalWrite (latchPin, HIGH);
}

void SegDispaly::clearRegister()
{
    setRegisterData (B00000000);
}

void SegDispaly::clearDisplay()
{
    // deactivate transistors
    for (int n = 0; n < 4; n++) digitalWrite (digitPins[n], HIGH);
}

//writes the temperature on display
void SegDispaly::updateDisplay()
{
    byte outByte;
    // dispaly digits
    for (int i = 0; i < 4; i++)
    {
        clearDisplay();
        clearRegister();

        // enable nth cell cathode (transistor)
        digitalWrite (digitPins[i], LOW); 

        // output nth digit on display
        if (i == 1)
        {
            //print the decimal point on the 2nd digit
            outByte = digit[digitBuffer[i]] | B10000000;
        }
        else outByte = digit[digitBuffer[i]];
        setRegisterData (outByte);

        //delayMicroseconds (500);
        delay (5);

        //Serial.print (outByte, BIN);
        //if (i == 3)
        //{
        //  Serial.println (".");
        //}
        //else Serial.print (", ");
    }
}

void SegDispaly::display (double value)
{
    int n = int (value * 100);
    digitBuffer[0] = n / 1000;
    digitBuffer[1] = (n % 1000) / 100;
    digitBuffer[2] = (n % 100) / 10;
    digitBuffer[3] = (n % 100) % 10;
    updateDisplay();
}

My target AVR is Arduino Uno R3, the code used to work fine in a sketch before I decided to create a library out of it. Any help would be greatly appreciated. thanks in advance.

2

You spelled the header filename wrong:

#include "SegDispaly.h"

should be:

#include "SegDisplay.h"

You have also made the same mistake in the class name multiple places in SegDisplay.cpp.

  • you know I checked the spelling of SegDisplay several times and couldn't spot it for some reason, I must be going blind. Thanks – user7342539 Aug 7 '17 at 22:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.