******* Creating First Library.. PROBLEMSSSSS!! as expected...

Hey,
I am relatively new to the Arduino world. At work I incorporate a lot of Teensy boards into my designs, I am the Mechanical Engineer so no software or firmware writing on my end. I began to get curious at to these little guys and got an Arduino. back story over.

I am trying to write a library based on SevSeg library. Mine will display characters on a 4dig sev seg display. I wrote a program that works great, however I would like to turn that into a library so I can simplify and reuse the function.

Here is the sketch that works:

int message[]={0,0,0,0,21,6,20,21,0,0,0,0};

int messagelength = 12;
int scrollspeed = 25;

int dig[4]={0,1,2,3};

int segA = 4;
int segB = 5;
int segC = 6;
int segD = 7;
int segE = 8;
int segF = 9;
int segG = 12;

int del=800;
int lightsensor = 1;
int lightsens;

int on = HIGH;
int off = LOW;

int m=0;
int n=0;


void setup()
{
  
  messagelength=messagelength-3;
  pinMode(dig[0],OUTPUT);
  pinMode(dig[1],OUTPUT);
  pinMode(dig[2],OUTPUT);
  pinMode(dig[3],OUTPUT);
  
  pinMode(segA,OUTPUT);
  pinMode(segB,OUTPUT);
  pinMode(segC,OUTPUT);
  pinMode(segD,OUTPUT);
  pinMode(segE,OUTPUT);
  pinMode(segF,OUTPUT);
  pinMode(segG,OUTPUT);
  
}


void loop()
{
  
 scrollmessage();
  
}
 
  
  
  
void scrollmessage()
{
  for(int m=0;m<messagelength;m++)
{
  for(int n=0;n<scrollspeed;n++)
  {
      digitalWrite(dig[0],LOW);
  digit(message[m]);
      delayMicroseconds(del);
      digitalWrite(dig[0],HIGH);
      delayMicroseconds(del);
              
      digitalWrite(dig[1],LOW);
  digit(message[m+1]);
      delayMicroseconds(del);
      digitalWrite(dig[1],HIGH);
      delayMicroseconds(del);
      
      digitalWrite(dig[2],LOW);
  digit(message[m+2]);
      delayMicroseconds(del);
      digitalWrite(dig[2],HIGH);
      delayMicroseconds(del);
      
      digitalWrite(dig[3],LOW);
  digit(message[m+3]);
      delayMicroseconds(del);
      digitalWrite(dig[3],HIGH);
      delayMicroseconds(del);
  }
      
}
}
  
// ---------------- TURN OFF ALL DISPLAYS  
void alloff()
{
  digitalWrite(dig[0],HIGH);
  digitalWrite(dig[1],HIGH);
  digitalWrite(dig[2],HIGH);
  digitalWrite(dig[3],HIGH);
}
  
  
  
  
  
  
  
  
  
  
  
  
  
  
// --------------------- LETTER CALLOUTS FOR DISPLAY  
  
int digit(int var)
{
  
  if(var<0)
  {
    var=0;
  }
  
switch (var)
{
  
case 0: //BLANK
  digitalWrite(segA,off);
  digitalWrite(segB,off);
  digitalWrite(segC,off);
  digitalWrite(segD,off);
  digitalWrite(segE,off);
  digitalWrite(segF,off);
  digitalWrite(segG,off);
  break;
  
  case 1:
  digitalWrite(segA,on);
  digitalWrite(segB,on);
  digitalWrite(segC,on);
  digitalWrite(segD,off);
  digitalWrite(segE,on);
  digitalWrite(segF,on);
  digitalWrite(segG,on);
  break;

case 2:
  digitalWrite(segA,off);
  digitalWrite(segB,off);
  digitalWrite(segC,on);
  digitalWrite(segD,on);
  digitalWrite(segE,on);
  digitalWrite(segF,on);
  digitalWrite(segG,on);
  break;

case 3:
  digitalWrite(segA,on);
  digitalWrite(segB,off);
  digitalWrite(segC,off);
  digitalWrite(segD,on);
  digitalWrite(segE,on);
  digitalWrite(segF,on);
  digitalWrite(segG,off);
  break;

case 4:
  digitalWrite(segA,off);
  digitalWrite(segB,off);
  digitalWrite(segC,off);
  digitalWrite(segD,on);
  digitalWrite(segE,on);
  digitalWrite(segF,off);
  digitalWrite(segG,on);
  break;

case 5:
  digitalWrite(segA,off);
  digitalWrite(segB,on);
  digitalWrite(segC,on);
  digitalWrite(segD,on);
  digitalWrite(segE,on);
  digitalWrite(segF,off);
  digitalWrite(segG,on);
  break;

case 6:
  digitalWrite(segA,on);
  digitalWrite(segB,off);
  digitalWrite(segC,off);
  digitalWrite(segD,on);
  digitalWrite(segE,on);
  digitalWrite(segF,on);
  digitalWrite(segG,on);
  break;

case 7:
  digitalWrite(segA,on);
  digitalWrite(segB,off);
  digitalWrite(segC,off);
  digitalWrite(segD,off);
  digitalWrite(segE,on);
  digitalWrite(segF,on);
  digitalWrite(segG,on);
  break;

case 8:
  digitalWrite(segA,on);
  digitalWrite(segB,on);
  digitalWrite(segC,on);
  digitalWrite(segD,on);
  digitalWrite(segE,off);
  digitalWrite(segF,on);
  digitalWrite(segG,on);
  break;

case 9:
  digitalWrite(segA,off);
  digitalWrite(segB,on);
  digitalWrite(segC,on);
  digitalWrite(segD,off);
  digitalWrite(segE,on);
  digitalWrite(segF,on);
  digitalWrite(segG,on);
  break;

case 10:
  digitalWrite(segA,off);
  digitalWrite(segB,off);
  digitalWrite(segC,on);
  digitalWrite(segD,off);
  digitalWrite(segE,on);
  digitalWrite(segF,on);
  digitalWrite(segG,on);
  break;

case 11:
  digitalWrite(segA,off);
  digitalWrite(segB,off);
  digitalWrite(segC,off);
  digitalWrite(segD,off);
  digitalWrite(segE,on);
  digitalWrite(segF,off);
  digitalWrite(segG,off);
  break;

case 12:
  digitalWrite(segA,off);
  digitalWrite(segB,off);
  digitalWrite(segC,off);
  digitalWrite(segD,off);
  digitalWrite(segE,on);
  digitalWrite(segF,on);
  digitalWrite(segG,off);
  break;

case 13:
  digitalWrite(segA,off);
  digitalWrite(segB,on);
  digitalWrite(segC,on);
  digitalWrite(segD,on);
  digitalWrite(segE,on);
  digitalWrite(segF,off);
  digitalWrite(segG,off);
  break;

case 14:
  digitalWrite(segA,off);
  digitalWrite(segB,off);
  digitalWrite(segC,off);
  digitalWrite(segD,on);
  digitalWrite(segE,on);
  digitalWrite(segF,on);
  digitalWrite(segG,off);
  break;

case 15:
  digitalWrite(segA,off);
  digitalWrite(segB,off);
  digitalWrite(segC,on);
  digitalWrite(segD,off);
  digitalWrite(segE,on);
  digitalWrite(segF,off);
  digitalWrite(segG,on);
  break;

case 16:
  digitalWrite(segA,on);
  digitalWrite(segB,on);
  digitalWrite(segC,on);
  digitalWrite(segD,on);
  digitalWrite(segE,on);
  digitalWrite(segF,on);
  digitalWrite(segG,off);
  break;

case 17:
  digitalWrite(segA,off);
  digitalWrite(segB,off);
  digitalWrite(segC,on);
  digitalWrite(segD,on);
  digitalWrite(segE,on);
  digitalWrite(segF,off);
  digitalWrite(segG,on);
  break;

case 18:
  digitalWrite(segA,on);
  digitalWrite(segB,on);
  digitalWrite(segC,off);
  digitalWrite(segD,off);
  digitalWrite(segE,on);
  digitalWrite(segF,on);
  digitalWrite(segG,on);
  break;

case 19:
  digitalWrite(segA,off);
  digitalWrite(segB,off);
  digitalWrite(segC,off);
  digitalWrite(segD,off);
  digitalWrite(segE,on);
  digitalWrite(segF,off);
  digitalWrite(segG,on);
  break;

case 20:
  digitalWrite(segA,on);
  digitalWrite(segB,off);
  digitalWrite(segC,on);
  digitalWrite(segD,on);
  digitalWrite(segE,off);
  digitalWrite(segF,on);
  digitalWrite(segG,on);
  break;

case 21:
  digitalWrite(segA,off);
  digitalWrite(segB,off);
  digitalWrite(segC,off);
  digitalWrite(segD,on);
  digitalWrite(segE,on);
  digitalWrite(segF,on);
  digitalWrite(segG,on);
  break;

case 22:
  digitalWrite(segA,off);
  digitalWrite(segB,on);
  digitalWrite(segC,on);
  digitalWrite(segD,on);
  digitalWrite(segE,on);
  digitalWrite(segF,on);
  digitalWrite(segG,off);
  break;

case 23:
  digitalWrite(segA,off);
  digitalWrite(segB,off);
  digitalWrite(segC,on);
  digitalWrite(segD,on);
  digitalWrite(segE,on);
  digitalWrite(segF,off);
  digitalWrite(segG,off);
 break;

case 24:
  digitalWrite(segA,off);
  digitalWrite(segB,on);
  digitalWrite(segC,on);
  digitalWrite(segD,on);
  digitalWrite(segE,on);
  digitalWrite(segF,on);
  digitalWrite(segG,off);
 break;
 
case 25:
  digitalWrite(segA,off);
  digitalWrite(segB,on);
  digitalWrite(segC,on);
  digitalWrite(segD,on);
  digitalWrite(segE,off);
  digitalWrite(segF,on);
  digitalWrite(segG,on);
  break;

case 26:
  digitalWrite(segA,on);
  digitalWrite(segB,on);
  digitalWrite(segC,off);
  digitalWrite(segD,on);
  digitalWrite(segE,on);
  digitalWrite(segF,off);
  digitalWrite(segG,on);
  break;
}
}

This scrolls the word “tESt” across the display over and over. Great.

See the attachments for the library files. They are not working, hence the Forum post.
I am getting lots of errors and cannot figure out what to change.

Please lend some advice/code fixing.

Thanks!
Ezoom404

SevSegmessage.cpp (7.37 KB)

SevSegmessage.h (697 Bytes)

You can make lib like attached code and I think no need to make class because this is a simple task. I did not tested code, you will take care of if any problem on code.

byte colPins[4] = { 0,1,2,3 };
byte segPins[7] = { 4,5,6,7,8,9,12 };

byte seg7digits[10][7] = { { 1,1,1,1,1,1,0 },  // = 0
                           { 0,1,1,0,0,0,0 },  // = 1
                           { 1,1,0,1,1,0,1 },  // = 2
                           { 1,1,1,1,0,0,1 },  // = 3
                           { 0,1,1,0,0,1,1 },  // = 4
                           { 1,0,1,1,0,1,1 },  // = 5
                           { 1,0,1,1,1,1,1 },  // = 6
                           { 1,1,1,0,0,0,0 },  // = 7
                           { 1,1,1,1,1,1,1 },  // = 8
                           { 1,1,1,0,0,1,1 }   // = 9
                           };

// Setup
void Seg7Init() {
  //
  for (byte i = 0; i < 4; ++i) {
    pinMode(colPins[i], OUTPUT);    
  }
  //
  for (byte i = 0; i < 7; ++i) {
     pinMode(segPins[i], OUTPUT);    
  }  
}

// write digit to given address    
void Seg7Write(byte col, byte digit) {  
  for (byte i = 0; i < 7; ++i) {   
     digitalWrite(segPins[i], seg7digits[digit][i]);   
  }
  
  digitalWrite(colPins[col], LOW);
}

//Blank the digit
void Seg7Off(byte col) {    
  digitalWrite(colPins[col], HIGH);  
}

//Blank all digits
void Seg7AllOff() {
  //
  for (byte i = 0; i < 4; ++i) {
    Seg7Off(i);
  }

See the attachments for the library files. They are not working, hence the Forum post.
I am getting lots of errors and cannot figure out what to change.

"They are not working" suggests that the code at least compiles and links. Apparently, yours does not. So, there is no possible definition of "working" that the code could possibly meet. So, it's irrelevant to even talk about working.

You are also keeping the errors to yourself. I'm not as inclined to help greedy people as I am to help those that share.

start by reading this http://arduino.cc/en/Hacking/LibraryTutorial
Best regards
Jantje