[Solved] 'Segment' does not name a type

Hello all,

I want to make a very simple library to control a few 7-segment LED displays with. I used the LibraryTutorial to base my library off of, and after solving most of the errors, I keep getting the following two:

sketch_feb07a:11: error: ‘Segment’ does not name a type
sketch_feb07a.cpp: In function ‘void loop()’:
sketch_feb07a:17: error: ‘segment’ was not declared in this scope

(Edit) This problem is solved, turns out it was a spelling mistake. I do have another batch of errors now though:
sketch_feb07a.cpp: In function ‘void loop()’:
sketch_feb07a:17: error: invalid conversion from ‘const int*’ to ‘int*’
sketch_feb07a:17: error: initializing argument 1 of ‘void Segments::write(int*)’

I get this error for all lines that refer to a CHAR_ const int in the loop().

My code consists of a few files, residing in my Sketches/Libraries folder. The IDE notices it’s there, because I can include my library. Here is my code:

sketch.ino

#include <Segments.h>

int segment1[8]  = {8,     // pin a
                    9,     // pin b
                    2,     // pin c
                    3,     // pin d
                    4,     // pin e
                    6,     // pin f
                    5,     // pin g
                    7};    // pin dp

Segment segment(segment1);

void setup() {
}

void loop() {
  segment.write(CHAR_0);
  delay(1000);
  segment.write(CHAR_1);
  delay(1000);
  segment.write(CHAR_2);
  delay(1000);
  segment.write(CHAR_3);
  delay(1000);
  segment.write(CHAR_4);
  delay(1000);
  segment.write(CHAR_5);
  delay(1000);
  segment.write(CHAR_6);
  delay(1000);
  segment.write(CHAR_7);
  delay(1000);
  segment.write(CHAR_8);
  delay(1000);
  segment.write(CHAR_9);
  delay(1000);
}

Segments.c

/*
  Segments.cpp - Library for writing to 7-segment displays
  Created by Thomas Baart, Februari 7, 2012
  Released into the public domain.
*/

#include "Segments.h"

Segments::Segments(int pinArray[8])
{
  for(int i = 0; i < 8; i++) {
    pinMode(pinArray[i], OUTPUT);
  }
  _pinArray[8] = pinArray[8];
}

void Segments::clear()
{
  for(int i = 0; i < 8, i++) {
    digitalWrite(_pinArray[i],LOW);
  }
}

void Segments::write(int CHAR[8]) {
  for(int i = 0; i < 8; i++) {
    digitalWrite(_pinArray[i],CHAR[i]);
  }
}

Segments.h

/*
  Segments.h - Library for writing to 7-segment displays
  Created by Thomas Baart, Februari 7, 2012
  Released into the public domain.
*/
#ifndef Segments_h
#define Segments_h

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


/*
  Public constants
*/
const int CHAR_0[8] = {1,1,1,1,1,1,0,0};
const int CHAR_1[8] = {0,1,1,0,0,0,0,0};
const int CHAR_2[8] = {1,1,0,1,1,0,1,0};
const int CHAR_3[8] = {1,1,1,1,0,0,1,0};
const int CHAR_4[8] = {0,1,1,0,0,1,1,0};
const int CHAR_5[8] = {1,0,1,1,1,0,1,0};
const int CHAR_6[8] = {1,0,1,1,1,1,1,0};
const int CHAR_7[8] = {1,1,1,0,0,0,0,0};
const int CHAR_8[8] = {1,1,1,1,1,1,1,0};
const int CHAR_9[8] = {1,1,1,1,0,1,1,0};

/*
  Definitions
*/
class Segments
{
  public:
    Segments(int pinArray[8]);
    void write(int character[8]);
    void clear();
  private:
    int _pinArray[8];
};

#endif

I’ve been searching these forums and google in general for about two hours now, but still haven’t found a solution that works for me. It’s probably some beginner’s mistake. Could you help me find a solution for these errors?

class Segments

Segment segment(segment1); // Missing an s
// ^

Oh wow, it really was a simple mistake. Thanks a lot, Coding Badly!

I do get another batch of errors now, though (of course):

sketch_feb07a.cpp: In function 'void loop()': sketch_feb07a:17: error: invalid conversion from 'const int*' to 'int*' sketch_feb07a:17: error: initializing argument 1 of 'void Segments::write(int*)'

And that for every reference I make to one of the const int CHAR_'s I have in the .h file. How would I go around defining those arrays, so I won't get the invalid conversion errors?

void Segments::write(const int CHAR[8]) {

Changed line 24 in Segments.c to void Segments::write(const int CHAR[8])

Still yields the same errors. While changing line 37 in Segments.h to void write(const int character[8]);

resolves the errors, it gives me entirely new ones:

In file included from /Users/thomasbaart/Documents/Arduino/libraries/Segments/Segments.c:7: /Users/thomasbaart/Documents/Arduino/libraries/Segments/Segments.h:33: error: expected '=', ',', ';', 'asm' or 'attribute' before 'Segments' /Users/thomasbaart/Documents/Arduino/libraries/Segments/Segments.c:9: error: expected '=', ',', ';', 'asm' or 'attribute' before ':' token /Users/thomasbaart/Documents/Arduino/libraries/Segments/Segments.c:17: error: expected '=', ',', ';', 'asm' or 'attribute' before ':' token /Users/thomasbaart/Documents/Arduino/libraries/Segments/Segments.c:24: error: expected '=', ',', ';', 'asm' or 'attribute' before ':' token

(Edit) I spotted another error in a for loop, I used a comma as separator instead of a semicolon. I really do need to be more careful. The code compiles now, but doesn't actually seem to do anything - not sure where the error lies. I'll try to debug this on my own for now, I suppose this new problem is for another day, and another thread, perhaps :)

Thanks again for the help, Coding Badly.