First Library - Works sometimes and sometimes gets stuck on "compiling sketch"

I’m not sure why but sometimes my code compiles and works just fine and other times it gets stuck on the “compiling sketch” part. I have rebooted my computer, tried it on new file with a different name but it still won’t compile! Any ideas?

Bubble_BackPack_Library_Rev_A

// Bubble backpack library: To add a library to make the device easy to use.
// UPDATED 6.2.2015



#include "BubbleBackpack.h"


void setup() {


}
void loop() {
  // Initiate the 
  BubbleBackpack displayz(13, 10 , 11);
  displayz.setUpDisplay(8, 1);
  displayz.setDisplayIntensity(1);
  //int digit, int value, int numDisplays
  //displayz.writeDigit(1 , 1 , 2);
  displayz.readFromSerial();
  //displayz.quickTest();
}

BubbleBackpack.cpp

#include "BubbleBackpack.h"

const static byte  digitReg[] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
const static byte  fontArray[] = {
  0b1111110, // 0
  0b0110000, // 1
  0b1101101, // 2
  0b1111001, // 3
  0b0110011, // 4
  0b1011011, // 5
  0b1011111, // 6
  0b1110000, // 7
  0b1111111, // 8
  0b1111011, // 9
  0b1110111, // 10  "A"
  0b0011111, // 11  "B"
  0b1001110, // 12  "C"
  0b0111101, // 13  "D"
  0b1001111, // 14  "E"
  0b1000111, // 15  "F"
};

//Sets up data pins connected to the display
// Free to use any digital IO pin but its best to avoid pin 0,1 and 13.
BubbleBackpack::BubbleBackpack(int clkPin, int csPin, int dinPin) {
  // Let the rest of the code know the csPin
  _csPin = csPin;
  _clkPin = clkPin;
  _dinPin = dinPin;
}

//Initates The Bubble Backpack in form: (Number of digits on the backpack (4 or 8), Number of backpacks cascaded together)
void BubbleBackpack::setUpDisplay(int numberOfDigits, int numberOfDisplays) {
  // initate the SPI pins
  pinMode(_csPin, OUTPUT);
  pinMode(_clkPin, OUTPUT);
  pinMode(_dinPin, OUTPUT);

  byte intensityReg = 0x0a; // 0 - 15
  byte modeReg = 0x0f;
  byte decodeReg = 0x09;
  byte scanReg = 0x0b;
  byte shutdownReg = 0x0c;

  //Let the rest of the program know how many displays and digits we have
  _cascadedDevices = numberOfDisplays;
  _numberOfDigits = numberOfDigits;

  //Set up every display
  for (int i = 1; i <= _cascadedDevices; i++) {
    // Turn off Test Mode
    spiTransfer(modeReg, 0, i);

    //Set the default display intensity to 6 out of 15
    spiTransfer(intensityReg, 6, i);

    //Turn off Shutdown Mode
    spiTransfer(shutdownReg, 1, i);

    // Put it into 'No Decode Mode'
    spiTransfer(decodeReg, 0, i);

    //Set Scan Rate (Depends on the number of digits on the display)
    spiTransfer(scanReg, (_numberOfDigits - 1), i);
  }
  clearDisplay();
}

// Clears the display
void BubbleBackpack::clearDisplay(void) {
  for (int c = 1; c <= _cascadedDevices; c++) {
    for (int i = 1; i < (_numberOfDigits + 1); i++) {
      spiTransfer(i, 0, c);
    }
  }
}

// Puts device in Shutdown Mode when a true value is passed down
// Takes device off shutdown mode when a false value is passed down
// Device still retains data and consumes about 150uA
void BubbleBackpack::shutDown(boolean shutItDown) {
  byte shutdownReg = 0x0c;
  if (shutItDown == true) {
    //For every display
    for (int i = 1; i <= _cascadedDevices; i++) {
      //Turn on Shutdown Mode
      spiTransfer(shutdownReg, 0, i);
    }
  }
  if (shutItDown == false) {
    //For every display
    for (int i = 1; i <= _cascadedDevices; i++) {
      //Turn off Shutdown Mode
      spiTransfer(shutdownReg, 1, i);
    }
  }
}

//Set the display intensity from 0 to 15
void BubbleBackpack::setDisplayIntensity(int intensity) {
  byte intensityReg = 0x0a; // 0 - 15

  // Set both displays to the same intensity
  for (int i = 1; i <= _cascadedDevices; i++) {
    //Set the display intensity to 6 out of 15
    spiTransfer(intensityReg, intensity, i);
  }
}

// Sets the digit at position 0 - 7 to the desired value
void BubbleBackpack::writeDigit(int digit, int value, int numDisplays) {
  // Turn off Test Mode
  spiTransfer(digitReg[digit], fontArray[value], numDisplays);
}

// Turns on a specific segment
// Segment value 0 = dot, A = 1 ... G = 7.
void BubbleBackpack::writeSegment(int digit, int segment, int numDisplays) {
  byte bits = 0;
  // Writes a one to bit at location 'segment'
  bitSet(bits, (7 - segment));
  spiTransfer(digitReg[digit], bits, numDisplays);
}

// Runs through 0 - 9 on every digit, on every display
void BubbleBackpack::quickTest(void) {
  for (int i = 1; i <= _cascadedDevices; i++) {
    for (int c = 0; c < 10; c++) {
      writeDigit(0, c, i);
      writeDigit(1, c, i);
      writeDigit(2, c, i);
      writeDigit(3, c, i);
      writeDigit(4, c, i);
      writeDigit(5, c, i);
      writeDigit(6, c, i);
      writeDigit(7, c, i);
      delay(500);
    }
  }
}

// Reads data from serial and writes it to the display
void BubbleBackpack::readFromSerial(void) {
  int input;
  int digitPosition = 0;

  Serial.begin(9600);

  Serial.println("Type a number or digit to display and press 'enter'");
  //stay in this loop so that the text does not get repeted or the variables reinitiated
  while (true) {
    input = Serial.read();
    // only write valid input data
    if (input != -1) {
      Serial.println("Digit sent to display");//Serial.println(input);
      for (int i = 1; i <= _cascadedDevices; i++) {
        writeDigit(digitPosition, input, i);
      }
      // reset counter back to zero
      if (digitPosition == (_numberOfDigits - 1)) {
        // set to -1 since it will always add one below
        digitPosition = -1;
      }
      digitPosition++;
    }
  }
}

void BubbleBackpack::spiTransfer(byte reg, byte data, int adress) {
  digitalWrite(_csPin, LOW);
  // Go up the cascade to the next chip if needed
  for (int i = adress; i < _cascadedDevices; i++) {
    // Send two bytes of 0s to push data to the appropriate chip
    shiftOut(_dinPin, _clkPin, MSBFIRST, 0);
    shiftOut(_dinPin, _clkPin, MSBFIRST, 0);
  }
  // Send Data and Register
  shiftOut(_dinPin, _clkPin, MSBFIRST, reg);
  shiftOut(_dinPin, _clkPin, MSBFIRST, data);
  // Go down the cascade to the previous chip if needed
  for (int i = 1; i < (_cascadedDevices - (_cascadedDevices - adress)) ; i++) {
    // Send two bytes of 0s to push data to  the appropriate chip
    shiftOut(_dinPin, _clkPin, MSBFIRST, 0);
    shiftOut(_dinPin, _clkPin, MSBFIRST, 0);
  }
  digitalWrite(_csPin, HIGH);
}

BubbleBackpack.h

#ifndef BubbleBackpack_H
#define BubbleBackpack_H

#include <avr/pgmspace.h>

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




class BubbleBackpack {
    int _csPin, _clkPin, _dinPin;
    int _numberOfDigits, _cascadedDevices;
  public:
    // Sets up data pins connected to the display
    // Free to use any digital IO pin but its best to avoid pin 0 and 1.
    BubbleBackpack(int clkPin, int csPin, int dinPin);

    // Initates The Bubble Backpack in form: (Number of digits on the backpack (4 or 8), Number of backpacks cascaded together)
    void setUpDisplay(int numberOfDigits, int numberOfDisplays);

    // Clears the display
    void clearDisplay(void);
    
    // Puts device in Shutdown Mode
    // Device still retains data and consumes about 150uA
    void shutDown(boolean shutItDown);

    // Set the display intensity from 0 to 15
    void setDisplayIntensity(int intensity);

    // Sets the digit at position 0 - 7 to the desired value
    void writeDigit(int digit, int value, int numDisplays);

    // Turns on a specific segment at 0 = dot, A = 1 ... G = 7.
    void writeSegment(int digit, int segment, int numDisplays);

    // Runs through 0 - 9 on every digit, on every display.
    void quickTest(void);

    // Reads data from serial and writes it to the display
    void readFromSerial(void);

    // Returns the number of  cascaded displays
    int numOfDisplays(void) {
      return _cascadedDevices;
    }

    // Returns the number of digits per display
    int numOfDigits(void) {
      return _numberOfDigits;
    }

    // Transfers data to the chip.
    // Adress 1 = first board, Adress 2 = the second cascaded board (one who's DIN is connected to the first board's DOUT)
    void spiTransfer(byte reg, byte data, int adress);
};

#endif

Bubblepack.h is in the same folder as your sketch?

I'm not really a software guy tho ...

I think I read somewhere that your .ino .h and .cpp files can't share the same filename name. Try renaming one of them.

CrossRoads: Bubblepack.h is in the same folder as your sketch?

Yep

chopsuwe: I think I read somewhere that your .ino .h and .cpp files can't share the same filename name. Try renaming one of them.

I changed it and it compiled now - lets hope that solved it and it will keep compiling. Thanks.