Pages: [1]   Go Down
Author Topic: 7 Segment Library problem  (Read 4801 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 15
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

i wanted to make a seven segment library so that there is no hotch-potch in the schematic.
the problem is the library is not working even in its initial stage.
please tell the bugs.
Here is the header file
Code:
/*
  SevenSeg.h - Library for using seven segment.
  Created by Raghvendra Mahashabde, September 23, 2012.
  Released into the public domain.
*/
#ifndef SevenSeg_h
#define SevenSeg_h

#include "Arduino.h"

class SevenSeg
{
  public:
    vaid begin(int pin1,int pin2,int pin3,int pin4,int pin5,int pin6,int pin7,int pin8);
    void displayNum(int input);
    void type(int common);
    void writeDot(byte dot);
  private:
    int pinList[8]={pin1,pin2,pin3,pin4,pin5,pin6,pin7,pin8};
    int _pin;
    int printPin;
    void sevenSegWrite(byte digit);
    void writeDot(byte dot);
    byte Hp;
    byte Lp;
    byte segCount
    byte seven_seg_digits[10][7] = { { Hp,Hp,Hp,Hp,Hp,Hp,Lp },  // = 0
                                       { Lp,Hp,Hp,Lp,Lp,Lp,Lp },  // = 1
                                                           { Hp,Hp,Lp,Hp,Hp,Lp,Hp},  // = 2
                                                           { Hp,Hp,Hp,Hp,Lp,Lp,Hp },  // = 3
                                                           { Lp,Hp,Hp,Lp,Lp,Hp,Hp },  // = 4
                                                           { Hp,Lp,Hp,Hp,Lp,Hp,Hp},  // = 5
                                                           { Hp,1,Hp,Hp,Hp,Hp,Hp },  // = 6
                                                           { Hp,Hp,Hp,Lp,Lp,Lp,Lp },  // = 7
                                                           { Hp,Hp,Hp,Hp,Hp,Hp,Hp },  // = 8
                                                           { Hp,Hp,Hp,Hp,Lp,Hp,Hp }   // = 9
 };
};

#endif
here is the c-file
Code:
#include "Arduino.h"
#include "SevenSeg.h"
void SevenSeg::begin(int pin1,int pin2,int pin3,int pin4,int pin5,int pin6,int pin7,int pin8)
{
pinMode(pinList[0],  OUTPUT); 
pinMode(pinList[1],  OUTPUT);
pinMode(pinList[2],  OUTPUT);
pinMode(pinList[3],  OUTPUT);
pinMode(pinList[4],  OUTPUT);
pinMode(pinList[5],  OUTPUT);
pinMode(pinList[6],  OUTPUT);
pinMode(pinList[7],  OUTPUT);
digitalWrite(pinList[0], Lp);
digitalWrite(pinList[1], Lp);
digitalWrite(pinList[2], Lp);
digitalWrite(pinList[3], Lp);
digitalWrite(pinList[4], Lp);
digitalWrite(pinList[5], Lp);
digitalWrite(pinList[6], Lp);
digitalWrite(pinList[7], Lp);

}

void SevenSeg::writeDot(byte dot) {
  digitalWrite(9, dot);
}
   
void sevenSegWrite(byte digit) {
  int printPin = 0;
  for (byte segCount = 0; segCount < 7; ++segCount) {
    digitalWrite(pinList[printPin], seven_seg_digits[digit][segCount]);
    ++printPin;
  }
}
void type(int common)
{
if(common==0)
{
byte Hp=1;
byte Lp=0;
}
else if(common==1)
{
byte Hp=0;
byte Lp=1;
}
}
void SevenSeg::displayNum(int input)
{
  if(input==0)
  {
    sevenSegWrite(0);
  }
  if(input==1)
  {
    sevenSegWrite(1);
  }
  if(input==2)
  {
    sevenSegWrite(2);
  }
  if(input==3)
  {
    sevenSegWrite(3);
  }
  if(input==4)
  {
    sevenSegWrite(4);
  }
  if(input==5)
  {
    sevenSegWrite(5);
  }
  if(input==6)
  {
    sevenSegWrite(6);
  }
  if(input==7)
  {
    sevenSegWrite(7);
  }
  if(input==8)
  {
    sevenSegWrite(8);
  }
  if(input==9)
  {
    sevenSegWrite(9);
  }
}

the working code is here
Code:
// Arduino 7 segment display example software
// http://www.hacktronics.com/Tutorials/arduino-and-7-segment-led.html
// License: http://www.opensource.org/licenses/mit-license.php (Go crazy)

 

// Define the LED digit patters, from 0 - 9
// Note that these patterns are for common cathode displays
// For common anode displays, change the 1's to 0's and 0's to 1's
// 1 = LED on, 0 = LED off, in this order:

//                                    Arduino pin: 2,3,4,5,6,7,8
byte seven_seg_digits[10][7] = { { 0,0,0,0,0,0,1 },  // = 0
                                                           { 1,0,0,1,1,1,1 },  // = 1
                                                           { 0,0,1,0,0,1,0 },  // = 2
                                                           { 0,0,0,0,1,1,0 },  // = 3
                                                           { 1,0,0,1,1,0,0 },  // = 4
                                                           { 0,1,0,0,1,0,0},  // = 5
                                                           { 0,1,0,0,0,0,0 },  // = 6
                                                           { 0,0,0,1,1,1,1 },  // = 7
                                                           { 0,0,0,0,0,0,0 },  // = 8
                                                           { 0,0,0,0,1,0,0 }   // = 9
                                                           };
                                                           
int e1=14,e2=15;                                                           

void setup() {               
  pinMode(2,  OUTPUT); 
  pinMode(3,  OUTPUT);
  pinMode(4,  OUTPUT);
  pinMode(5,  OUTPUT);
  pinMode(6,  OUTPUT);
  pinMode(7,  OUTPUT);
  pinMode(8,  OUTPUT);
  pinMode(9,  OUTPUT);
  pinMode(e1, OUTPUT);
  pinMode(e2, OUTPUT);
  writeDot(1);  // start with the "dot" off
}

void writeDot(byte dot) {
  digitalWrite(9, dot);
}
   
void sevenSegWrite(byte digit) {
  byte pin = 2;
  for (byte segCount = 0; segCount < 7; ++segCount) {
    digitalWrite(pin, seven_seg_digits[digit][segCount]);
    ++pin;
  }
}

void loop() {
 for(int number=0; number<100; number++)
  {
  int U,T;
  U=number%10;
  T=(number/10)%10;
  for(int i=0;i<125;i++)
  {
  digitalWrite(e1, 1);
  digitalWrite(e2, 0);
  segase(U);
  writeDot(1);
  delay(2);
  digitalWrite(e1, 0);
  digitalWrite(e2, 1);
  segase(T);
  writeDot(0);
  delay(2);
  }
  }
}

void segase(int input)
{
  if(input==0)
  {
    sevenSegWrite(0);
  }
  if(input==1)
  {
    sevenSegWrite(1);
  }
  if(input==2)
  {
    sevenSegWrite(2);
  }
  if(input==3)
  {
    sevenSegWrite(3);
  }
  if(input==4)
  {
    sevenSegWrite(4);
  }
  if(input==5)
  {
    sevenSegWrite(5);
  }
  if(input==6)
  {
    sevenSegWrite(6);
  }
  if(input==7)
  {
    sevenSegWrite(7);
  }
  if(input==8)
  {
    sevenSegWrite(8);
  }
  if(input==9)
  {
    sevenSegWrite(9);
  }
}
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 547
Posts: 45935
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
the problem is the library is not working even in its initial stage.
You have the hardware. You have some expectations about what the software will do. You have the visual feedback on what that software actually does. You know what the differences are between your expectations and your reality are.

And, yet, you'd like for us to help you debug the library.

I think it is just possible that you might need to provide some more details.
Logged

Brest, France
Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello,
 try this library I wrote recently:
http://laurent.le.goff.free.fr/blog/IMG/zip/sevenseg.zip
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 15
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

does anyone know of an externel compiler???
arduino is not compiling the library properly and says there are various errors.
here is the edited SevenSeg.cpp
Code:
int pin1,pin2,pin3,pin4,pin5,pin6,pin7,pin8;
#include "Arduino.h"
#include "SevenSeg.h"
byte pinListin[8]={pin1,pin2,pin3,pin4,pin5,pin6,pin7,pin8};
void SevenSeg::begin(int pin1,int pin2,int pin3,int pin4,int pin5,int pin6,int pin7,int pin8)
{
pinMode(pinListin[0],  OUTPUT); 
pinMode(pinListin[1],  OUTPUT);
pinMode(pinListin[2],  OUTPUT);
pinMode(pinListin[3],  OUTPUT);
pinMode(pinListin[4],  OUTPUT);
pinMode(pinListin[5],  OUTPUT);
pinMode(pinListin[6],  OUTPUT);
pinMode(pinListin[7],  OUTPUT);
digitalWrite(pinListin[0], Lp);
digitalWrite(pinListin[1], Lp);
digitalWrite(pinListin[2], Lp);
digitalWrite(pinListin[3], Lp);
digitalWrite(pinListin[4], Lp);
digitalWrite(pinListin[5], Lp);
digitalWrite(pinListin[6], Lp);
digitalWrite(pinListin[7], Lp);
}

void SevenSeg::writeDot(byte dot) {
  digitalWrite(pinListin[7], dot);
}
byte seven_seg_digits[10][7] = { { Hp,Hp,Hp,Hp,Hp,Hp,Lp },  // = 0
                                    { Lp,Hp,Hp,Lp,Lp,Lp,Lp },  // = 1
                                    { Hp,Hp,Lp,Hp,Hp,Lp,Hp},  // = 2
                                    { Hp,Hp,Hp,Hp,Lp,Lp,Hp },  // = 3
                                    { Lp,Hp,Hp,Lp,Lp,Hp,Hp },  // = 4
                                    { Hp,Lp,Hp,Hp,Lp,Hp,Hp},  // = 5
                                    { Hp,1,Hp,Hp,Hp,Hp,Hp },  // = 6
                                    { Hp,Hp,Hp,Lp,Lp,Lp,Lp },  // = 7
                                    { Hp,Hp,Hp,Hp,Hp,Hp,Hp },  // = 8
                                    { Hp,Hp,Hp,Hp,Lp,Hp,Hp }   // = 9
 };
void SevenSeg::type(int common)
{
if(common==0)
{
byte Hp=1;
byte Lp=0;
}
else if(common==1)
{
byte Hp=0;
byte Lp=1;
}
}
void SevenSeg::displayNum(int input)
{
  if(input==0)
  {
    int printPin = 0;
  for (byte segCount = 0; segCount < 7; ++segCount) {
    digitalWrite(pinListin[printPin], seven_seg_digits[0][segCount]);
    ++printPin;
  }
  if(input==1)
  {
    int printPin = 0;
  for (byte segCount = 0; segCount < 7; ++segCount) {
    digitalWrite(pinListin[printPin], seven_seg_digits[1][segCount]);
    ++printPin;
  }
  if(input==2)
  {
   int printPin = 0;
  for (byte segCount = 0; segCount < 7; ++segCount) {
    digitalWrite(pinListin[printPin], seven_seg_digits[2][segCount]);
    ++printPin;
  }
  if(input==3)
  {
   int printPin = 0;
  for (byte segCount = 0; segCount < 7; ++segCount) {
    digitalWrite(pinListin[printPin], seven_seg_digits[3][segCount]);
    ++printPin;
  }
  if(input==4)
  {
    int printPin = 0;
  for (byte segCount = 0; segCount < 7; ++segCount) {
    digitalWrite(pinListin[printPin], seven_seg_digits[4][segCount]);
    ++printPin;
  }
  if(input==5)
  {
    int printPin = 0;
  for (byte segCount = 0; segCount < 7; ++segCount) {
    digitalWrite(pinListin[printPin], seven_seg_digits[5][segCount]);
    ++printPin;
  }
  if(input==6)
  {
    int printPin = 0;
  for (byte segCount = 0; segCount < 7; ++segCount) {
    digitalWrite(pinListin[printPin], seven_seg_digits[6][segCount]);
    ++printPin;
  }
  if(input==7)
  {
    int printPin = 0;
  for (byte segCount = 0; segCount < 7; ++segCount) {
    digitalWrite(pinListin[printPin], seven_seg_digits[7][segCount]);
    ++printPin;
  }
  if(input==8)
  {
    int printPin = 0;
  for (byte segCount = 0; segCount < 7; ++segCount) {
    digitalWrite(pinListin[printPin], seven_seg_digits[8][segCount]);
    ++printPin;
  }
  if(input==9)
  {
    int printPin = 0;
  for (byte segCount = 0; segCount < 7; ++segCount) {
    digitalWrite(pinListin[printPin], seven_seg_digits[9][segCount]);
    ++printPin;
  }
}
and here is the edited header file
Code:
/*
  SevenSeg.h - Library for using seven segment.
  Created by Raghvendra Mahashabde, September 23, 2012.
  Released into the public domain.
*/
#ifndef SevenSeg_h
#define SevenSeg_h

#include "Arduino.h"

class SevenSeg
{
  public:
    void begin(int pin1,int pin2,int pin3,int pin4,int pin5,int pin6,int pin7,int pin8);
    void displayNum(int input);
    void type(int common);
    void writeDot(byte dot);
  private:
    byte pinListin;
    int printPin;
    byte Hp;
    byte Lp;
    byte segCount;
    byte seven_seg_digits;
};

#endif
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 547
Posts: 45935
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
does anyone know of an externel compiler???
arduino is not compiling the library properly and says there are various errors.
Then, fix them. Any other compiler is going to tell you the same things.

Code:
byte pinListin[8]={pin1,pin2,pin3,pin4,pin5,pin6,pin7,pin8};
Exactly what values did you just store in this array? What values are in pin1, pin2, etc.? Since they appear to be global variables, they are all initialized to 0.

Code:
void SevenSeg::begin(int pin1,int pin2,int pin3,int pin4,int pin5,int pin6,int pin7,int pin8)
{
pinMode(pinListin[0],  OUTPUT); 
pinMode(pinListin[1],  OUTPUT);
pinMode(pinListin[2],  OUTPUT);
pinMode(pinListin[3],  OUTPUT);
pinMode(pinListin[4],  OUTPUT);
pinMode(pinListin[5],  OUTPUT);
pinMode(pinListin[6],  OUTPUT);
pinMode(pinListin[7],  OUTPUT);
You pass a list of pins to the function, then set some other pins. Why? Why bother passing pins to the function if you aren't going to use them?

Code:
void SevenSeg::writeDot(byte dot) {
  digitalWrite(pinListin[7], dot);
}
Writing to the serial port pin is rarely a good idea.

Code:
byte seven_seg_digits[10][7] = { { Hp,Hp,Hp,Hp,Hp,Hp,Lp },  // = 0
                                    { Lp,Hp,Hp,Lp,Lp,Lp,Lp },  // = 1
                                    { Hp,Hp,Lp,Hp,Hp,Lp,Hp},  // = 2
                                    { Hp,Hp,Hp,Hp,Lp,Lp,Hp },  // = 3
                                    { Lp,Hp,Hp,Lp,Lp,Hp,Hp },  // = 4
                                    { Hp,Lp,Hp,Hp,Lp,Hp,Hp},  // = 5
                                    { Hp,1,Hp,Hp,Hp,Hp,Hp },  // = 6
                                    { Hp,Hp,Hp,Lp,Lp,Lp,Lp },  // = 7
                                    { Hp,Hp,Hp,Hp,Hp,Hp,Hp },  // = 8
                                    { Hp,Hp,Hp,Hp,Lp,Hp,Hp }   // = 9
 };
Where have you assigned values to Hp and Lp? The values are class members. The array is not. You can't use class members this way.

The displayNum() function is atrocious. The only difference I see between the blocks of code is that the index into the seven_seg_digits array changes, to be whatever input was. Just use input in place of the hardcoded value, and get rid of 90% of your code.

A for statement can declare and operate on multiple variables.
Code:
for(byte printPin = 0, seqCount = 0; seqCount < 7; seqCount++, printPin++)
{
}
Although why you need two values that always contain the same value is a mystery.

Finally, you have not said what the compiler is complaining about, so its hard to really help you.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 15
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Exactly what values did you just store in this array? What values are in pin1, pin2, etc.? Since they appear to be global variables, they are all initialized to 0.
the values pin1, pin2 etc are the pin numbers where 7 segment pins are connected to the arduino.
Quote
Writing to the serial port pin is rarely a good idea.
pinListin[7] is an location of the pin8 which is the dot pin of the 7 segment.
how come it is a serial port pin, please specify.
i have made some changes in the cpp file and the header file according to your additions.

Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 15
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

here is the new c file
Code:
#include "Arduino.h"
#include "SevenSeg.h"

void SevenSeg::begin(byte pin1,byte pin2,byte pin3,byte pin4,byte pin5,byte pin6,byte pin7,byte pin8)
{
byte pinListin[8]={pin1,pin2,pin3,pin4,pin5,pin6,pin7,pin8};
pinMode(pinListin[0],  OUTPUT); 
pinMode(pinListin[1],  OUTPUT);
pinMode(pinListin[2],  OUTPUT);
pinMode(pinListin[3],  OUTPUT);
pinMode(pinListin[4],  OUTPUT);
pinMode(pinListin[5],  OUTPUT);
pinMode(pinListin[6],  OUTPUT);
pinMode(pinListin[7],  OUTPUT);
digitalWrite(pinListin[0], Lp);
digitalWrite(pinListin[1], Lp);
digitalWrite(pinListin[2], Lp);
digitalWrite(pinListin[3], Lp);
digitalWrite(pinListin[4], Lp);
digitalWrite(pinListin[5], Lp);
digitalWrite(pinListin[6], Lp);
digitalWrite(pinListin[7], Lp);
}
void SevenSeg::writeDot(byte dot) {
  digitalWrite(pin8, dot);
}

void SevenSeg::type(int common)
{
if(common==0)
{
byte Hp=1;
byte Lp=0;
}
else if(common==1)
{
byte Hp=0;
byte Lp=1;
}

byte seven_seg_digits[10][7] = { { Hp,Hp,Hp,Hp,Hp,Hp,Lp }, 
                                    { Lp,Hp,Hp,Lp,Lp,Lp,Lp },
                                    { Hp,Hp,Lp,Hp,Hp,Lp,Hp},
                                    { Hp,Hp,Hp,Hp,Lp,Lp,Hp },
                                    { Lp,Hp,Hp,Lp,Lp,Hp,Hp },
                                    { Hp,Lp,Hp,Hp,Lp,Hp,Hp}, 
                                    { Hp,1,Hp,Hp,Hp,Hp,Hp },
                                    { Hp,Hp,Hp,Lp,Lp,Lp,Lp },
                                    { Hp,Hp,Hp,Hp,Hp,Hp,Hp },
                                    { Hp,Hp,Hp,Hp,Lp,Hp,Hp } 
 };
}
void SevenSeg::displayNum(int input)
{
  if(input==0)
  {
    for (byte segCount = 0; segCount < 7; ++segCount) {
    digitalWrite(pinListin[segCount], seven_seg_digits[0][segCount]);
  }}
  if(input==1)
  {
  for (byte segCount = 0; segCount < 7; ++segCount) {
  digitalWrite(pinListin[segCount], seven_seg_digits[1][segCount]);
 
  }}
  if(input==2)
  {
 
  for (byte segCount = 0; segCount < 7; ++segCount) {
    digitalWrite(pinListin[segCount], seven_seg_digits[2][segCount]);

  }}
  if(input==3)
  {

  for (byte segCount = 0; segCount < 7; ++segCount) {
    digitalWrite(pinListin[segCount], seven_seg_digits[3][segCount]);

  }}
  if(input==4)
  {

  for (byte segCount = 0; segCount < 7; ++segCount) {
    digitalWrite(pinListin[segCount], seven_seg_digits[4][segCount]);

  }}
  if(input==5)
  {

  for (byte segCount = 0; segCount < 7; ++segCount) {
    digitalWrite(pinListin[segCount], seven_seg_digits[5][segCount]);

  }}
  if(input==6)
  {

  for (byte segCount = 0; segCount < 7; ++segCount) {
    digitalWrite(pinListin[segCount], seven_seg_digits[6][segCount]);

  }}
  if(input==7)
  {

  for (byte segCount = 0; segCount < 7; ++segCount) {
    digitalWrite(pinListin[segCount], seven_seg_digits[7][segCount]);

  }}
  if(input==8)
  {

  for (byte segCount = 0; segCount < 7; ++segCount) {
    digitalWrite(pinListin[segCount], seven_seg_digits[8][segCount]);

  }}
  if(input==9)
  {

  for (byte segCount = 0; segCount < 7; ++segCount) {
    digitalWrite(pinListin[segCount], seven_seg_digits[9][segCount]);

  }}
}
and here are the errors which i could note resolve
Code:




C:\Users\raghav\Downloads\arduino-1.0.1-windows\arduino-1.0.1\libraries\SevenSeg\SevenSeg.cpp: In member function 'void SevenSeg::writeDot(byte)':
C:\Users\raghav\Downloads\arduino-1.0.1-windows\arduino-1.0.1\libraries\SevenSeg\SevenSeg.cpp:25: error: 'pin8' was not declared in this scope
C:\Users\raghav\Downloads\arduino-1.0.1-windows\arduino-1.0.1\libraries\SevenSeg\SevenSeg.cpp: In member function 'void SevenSeg::displayNum(int)':
C:\Users\raghav\Downloads\arduino-1.0.1-windows\arduino-1.0.1\libraries\SevenSeg\SevenSeg.cpp:58: error: invalid types 'byte[byte]' for array subscript
C:\Users\raghav\Downloads\arduino-1.0.1-windows\arduino-1.0.1\libraries\SevenSeg\SevenSeg.cpp:58: error: invalid types 'byte[int]' for array subscript
C:\Users\raghav\Downloads\arduino-1.0.1-windows\arduino-1.0.1\libraries\SevenSeg\SevenSeg.cpp:63: error: invalid types 'byte[byte]' for array subscript
C:\Users\raghav\Downloads\arduino-1.0.1-windows\arduino-1.0.1\libraries\SevenSeg\SevenSeg.cpp:63: error: invalid types 'byte[int]' for array subscript
C:\Users\raghav\Downloads\arduino-1.0.1-windows\arduino-1.0.1\libraries\SevenSeg\SevenSeg.cpp:70: error: invalid types 'byte[byte]' for array subscript
C:\Users\raghav\Downloads\arduino-1.0.1-windows\arduino-1.0.1\libraries\SevenSeg\SevenSeg.cpp:70: error: invalid types 'byte[int]' for array subscript
C:\Users\raghav\Downloads\arduino-1.0.1-windows\arduino-1.0.1\libraries\SevenSeg\SevenSeg.cpp:77: error: invalid types 'byte[byte]' for array subscript
C:\Users\raghav\Downloads\arduino-1.0.1-windows\arduino-1.0.1\libraries\SevenSeg\SevenSeg.cpp:77: error: invalid types 'byte[int]' for array subscript
C:\Users\raghav\Downloads\arduino-1.0.1-windows\arduino-1.0.1\libraries\SevenSeg\SevenSeg.cpp:84: error: invalid types 'byte[byte]' for array subscript
C:\Users\raghav\Downloads\arduino-1.0.1-windows\arduino-1.0.1\libraries\SevenSeg\SevenSeg.cpp:84: error: invalid types 'byte[int]' for array subscript
C:\Users\raghav\Downloads\arduino-1.0.1-windows\arduino-1.0.1\libraries\SevenSeg\SevenSeg.cpp:91: error: invalid types 'byte[byte]' for array subscript
C:\Users\raghav\Downloads\arduino-1.0.1-windows\arduino-1.0.1\libraries\SevenSeg\SevenSeg.cpp:91: error: invalid types 'byte[int]' for array subscript
C:\Users\raghav\Downloads\arduino-1.0.1-windows\arduino-1.0.1\libraries\SevenSeg\SevenSeg.cpp:98: error: invalid types 'byte[byte]' for array subscript
C:\Users\raghav\Downloads\arduino-1.0.1-windows\arduino-1.0.1\libraries\SevenSeg\SevenSeg.cpp:98: error: invalid types 'byte[int]' for array subscript
C:\Users\raghav\Downloads\arduino-1.0.1-windows\arduino-1.0.1\libraries\SevenSeg\SevenSeg.cpp:105: error: invalid types 'byte[byte]' for array subscript
C:\Users\raghav\Downloads\arduino-1.0.1-windows\arduino-1.0.1\libraries\SevenSeg\SevenSeg.cpp:105: error: invalid types 'byte[int]' for array subscript
C:\Users\raghav\Downloads\arduino-1.0.1-windows\arduino-1.0.1\libraries\SevenSeg\SevenSeg.cpp:112: error: invalid types 'byte[byte]' for array subscript
C:\Users\raghav\Downloads\arduino-1.0.1-windows\arduino-1.0.1\libraries\SevenSeg\SevenSeg.cpp:112: error: invalid types 'byte[int]' for array subscript
C:\Users\raghav\Downloads\arduino-1.0.1-windows\arduino-1.0.1\libraries\SevenSeg\SevenSeg.cpp:119: error: invalid types 'byte[byte]' for array subscript
C:\Users\raghav\Downloads\arduino-1.0.1-windows\arduino-1.0.1\libraries\SevenSeg\SevenSeg.cpp:119: error: invalid types 'byte[int]' for array subscript

con you name an externel compiler that is handy and can be used just to compile c++/arduino
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 547
Posts: 45935
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
the values pin1, pin2 etc are the pin numbers where 7 segment pins are connected to the arduino.
No, they were not.

Code:
int pin1,pin2,pin3,pin4,pin5,pin6,pin7,pin8;
#include "Arduino.h"
#include "SevenSeg.h"
byte pinListin[8]={pin1,pin2,pin3,pin4,pin5,pin6,pin7,pin8};
pin2 to pin8 are global variables. Global variables are always initialized. Since you didn't supply initializers, the compiler did. It supplied 0. So, you now have an array full of zeros.

Looking at your latest code:
Code:
byte pinListin[8]={pin1,pin2,pin3,pin4,pin5,pin6,pin7,pin8};
This array is local to setup. Since you never reference this array in a for loop, it is rather a waste of time to have created it.

Code:
if(common==0)
{
byte Hp=1;
byte Lp=0;
}
else if(common==1)
{
byte Hp=0;
byte Lp=1;
}
More local variables that immediately go out of scope.

Spending some time learning about scope would be time well spent.

Code:
byte seven_seg_digits[10][7] = { { Hp,Hp,Hp,Hp,Hp,Hp,Lp }, 
                                    { Lp,Hp,Hp,Lp,Lp,Lp,Lp },
                                    { Hp,Hp,Lp,Hp,Hp,Lp,Hp},
                                    { Hp,Hp,Hp,Hp,Lp,Lp,Hp },
                                    { Lp,Hp,Hp,Lp,Lp,Hp,Hp },
                                    { Hp,Lp,Hp,Hp,Lp,Hp,Hp}, 
                                    { Hp,1,Hp,Hp,Hp,Hp,Hp },
                                    { Hp,Hp,Hp,Lp,Lp,Lp,Lp },
                                    { Hp,Hp,Hp,Hp,Hp,Hp,Hp },
                                    { Hp,Hp,Hp,Hp,Lp,Hp,Hp } 
 };
The member variables, Hp and Lp STILL do not have values.

Not that it matters, because that array is not the same as the member variable that is referenced in SevenSeg::displayNum().

The errors all refer to the fact that displayNum() is referring to the class member seven_seg_digits, which is a byte, not the global variable seven_seg_digits that is a two dimensional array.

Obviously, your problem is that you are having trouble initializing the array in the source code when the array is defined in the header. So, you are dancing all over the place trying to invent shortcuts. There are none.

Suck it up and initialize the member array one element at a time.

And no not, EVER, create local variables with the same name as global variables OR as member variables. Period.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 15
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
thanks for the configurations but your library mayby only works for 4xsevensegment displays like that from sparkfun
i make my own boards of seven segment.
i managed to finally compile the library.
but when i enter any command in it,it gives error
Quote
sketch_oct02a.cpp: In function 'void setup()':
sketch_oct02a:3: error: expected unqualified-id before '.' token
sketch_oct02a:4: error: expected unqualified-id before '.' token
here is the code which i ran
Code:
#include <sevensegment.h>
void setup()
{
  sevensegment.pinn(2,3,4,5,6,7,8,9);
  sevensegment.type(1);
}
void loop()
{
}

Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 547
Posts: 45935
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Where did you define a variable named sevensegment? Nowhere. That is why the compiler is telling you that you can't use that name before the . in:
Code:
  sevensegment.pinn(2,3,4,5,6,7,8,9);
  sevensegment.type(1);

Did you look at the supplied examples?
Logged

Brest, France
Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
thanks for the configurations but your library mayby only works for 4xsevensegment displays like that from sparkfun

This library work from 2 digits to 8 digits, and is suitable for common cathode and common anode.
yesterday i modify the library to add the choice of drive common by transistor or directly by arduino pin.
http://laurent.le.goff.free.fr/blog/IMG/zip/sevenseg.zip

example for 2 digit:
Code:
#include <SevenSeg.h>

/* SevenSeg (Anode or Cathode, Direct or Transistor,a,b,c,d,e,f,g,dp,com1,com2)  [com2 -> com8] */
SevenSeg display2x7(Anode,Transistor,0,1,2,3,4,5,6,7,8,9);

void setup()
{
}

void loop()
{
     display2x7.println(millis()/1000);
     display2x7.multiplex();     //digit 1 on
     delay(10);                  //10ms*2=20ms -> 50hz multiplex
     display2x7.multiplex();     //digit 2 on
     delay(10);
}


example with library MsTimer2

Code:
/*
  7 segments Libraries
 
 Demonstrates the use a 7 segments display.
 
 This sketch prints " OK." and count 0.1ms.
 
  The circuit:
 * Segment a pin to Resistor 680 to digital pin 0
 * Segment b pin to Resistor 680 to digital pin 1
 * Segment c pin to Resistor 680 to digital pin 2
 * Segment d pin to Resistor 680 to digital pin 3
 * Segment e pin to Resistor 680 to digital pin 4
 * Segment f pin to Resistor 680 to digital pin 5
 * Segment g pin to Resistor 680 to digital pin 6
 * Segment dp pin to Resistor 680 to digital pin 7
 * Common Anode 1 pin to digital pin 8
 * Common Anode 2 pin to digital pin 9
 * Common Anode 3 pin to digital pin 10
 * Common Anode 4 pin to digital pin 11
 
 Library originally write 1 Sep 2012 by Laurent LE GOFF
 
 This example code is in the public domain.
 */
#include <SevenSeg.h>
#include <MsTimer2.h>

/* SevenSeg (Anode or Cathode, Direct or Transistor,a,b,c,d,e,f,g,dp,com1,com2,com3,com4)  [com2 -> com8] */
SevenSeg afficheur(Anode,Direct,0,1,2,3,4,5,6,7,8,9,10,11);

void setup()
{
  MsTimer2::set(5, interrupt); // 50Hz
  MsTimer2::start();
  afficheur.cursor();
  delay(5000);
  afficheur.setCursor(2);
  afficheur.print('O');
  delay(1000);
  afficheur.print('K');
  delay(1000);
  afficheur.print('.');
  delay(3000);
  afficheur.home();
  delay(3000);
  afficheur.noDisplay();
  delay(1000);
  afficheur.display();
  afficheur.noCursor();
  afficheur.clear();

}

void interrupt()
{
  afficheur.multiplex();
}

void loop()
{
  afficheur.println(millis()/100);
}
« Last Edit: October 04, 2012, 07:16:19 am by llegoff » Logged

Pages: [1]   Go Up
Jump to: